Re: [PHP] Constraint Violation when INSERT

2003-12-10 Thread Sven
[EMAIL PROTECTED] schrieb:


Hi all, 

I got the error  Constraint Violation  when I did an INSERT . 
Gone thru the code umpteen times but to no avail..Wondering 
where my error 
was??...Below is a snip of the block of code: 

 
? 
$dsn = mysql://root:[EMAIL PROTECTED]/tablename; 

$db = DB::connect ($dsn); 
  if (DB::isError ($db)) 
  die ($db-getMessage()); 

//create variables ready to go into DB 

$tutor_name = $db-quote($_POST[tutor_name]); 
$tutor_contact = $db-quote($_POST[tutor_contact]); 
$tutor_email = $db-quote($_POST[tutor_email]); 
$tutor_profile = $db-quote($_POST[tutor_profile]); 

$sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,   
tutor_profile) 
   VALUES 
($tutor_name,$tutor_contact,$tutor_email,$tutor_profile); 

$result = $db-query($sql); 
if( DB::isError($result) ) { 
   die ($result-getMessage()); 
} 
? 

-- 
- 
Everything was fine and the INSERT works, user input was 
insert into the 
database successful using the same block of code but the next 
thing i know I 
got this error anyone know watz the proz here??? 
Hope to get some help soon. Thanks in advance=) 

Irin. 


Don't you need to quote your strings? 

$sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,   
tutor_profile) 
VALUES 
('$tutor_name','$tutor_contact','$tutor_email','$tutor_profile'); 

Martin 

--

Yes, I actually quoted my string at the beginning but whenever i do 
an INSERT it actually insert a NULL value into the fields...why is this 
so???So I try not to quote the strings but I got a Contraints Violation 
errorWhat could be the problem??

--
Hope to get some help soon. All help are greatly appreciated.


Irin.
hi,

i don't know this db-class, but it seems that $db-quote() already 
quotes your values. so first take a look what comes from your form:

?php
var_export($_POST);
?
then, take a look what this quote-method does with your vals. eg:

?php
var_export($tutor_name);
?
if these vars constist of your information try to setup qour query 
according to mysql manual, depending on the values in your vars.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Constraint Violation when INSERT

2003-12-10 Thread Sophie Mattoug

Hi all,
I got the error  Constraint Violation  when I did an INSERT . 
Gone thru the code umpteen times but to no avail..Wondering where my 
error was??...Below is a snip of the block of code:
 ? $dsn = 
mysql://root:[EMAIL PROTECTED]/tablename;
$db = DB::connect ($dsn);   if (DB::isError ($db))   die 
($db-getMessage());

//create variables ready to go into DB
$tutor_name = $db-quote($_POST[tutor_name]); $tutor_contact = 
$db-quote($_POST[tutor_contact]); $tutor_email = 
$db-quote($_POST[tutor_email]); $tutor_profile = 
$db-quote($_POST[tutor_profile]);

$sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,   
tutor_profile)VALUES 
($tutor_name,$tutor_contact,$tutor_email,$tutor_profile);

$result = $db-query($sql); if( DB::isError($result) ) {die 
($result-getMessage()); } ?
-- 
- Everything was fine and the INSERT works, user input was 
insert into the database successful using the same block of code but 
the next thing i know I got this error anyone know watz the proz 
here??? Hope to get some help soon. Thanks in advance=)
Irin. 

It looks like you have a constraint in your table, ie some of the values 
must correspond to another receord of another table for example... Could 
you post a MySQL description of your table ?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Constraint Violation when INSERT

2003-12-10 Thread irinchiang

 Hi all, 
 I got the error  Constraint Violation  when I did an INSERT . 
 Gone thru the code umpteen times but to no avail..Wondering where my 
 error was??...Below is a snip of the block of code: 
  ? $dsn = 
 mysql://root:[EMAIL PROTECTED]/tablename; 
 $db = DB::connect ($dsn);   if (DB::isError ($db))   die 
 ($db-getMessage()); 
 
 //create variables ready to go into DB 
 $tutor_name = $db-quote($_POST[tutor_name]); $tutor_contact = 
 $db-quote($_POST[tutor_contact]); $tutor_email = 
 $db-quote($_POST[tutor_email]); $tutor_profile = 
 $db-quote($_POST[tutor_profile]); 
 
 $sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,   
 tutor_profile)VALUES 
 ($tutor_name,$tutor_contact,$tutor_email,$tutor_profile); 
 
 $result = $db-query($sql); if( DB::isError($result) ) {die 
 ($result-getMessage()); } ? 
 -- 
 - Everything was fine and the INSERT works, user input was 
 insert into the database successful using the same block of code but 
 the next thing i know I got this error anyone know watz the proz 
 here??? Hope to get some help soon. Thanks in advance=) 
 Irin. 
 

It looks like you have a constraint in your table, ie some of the values 
must correspond to another receord of another table for example... Could 
you post a MySQL description of your table ? 

---

But I was only trying out the script using one table and that is why there's 
no way I can have some of my values corresponding to another table...
I'm quite a newbie to database design, so having only one table meaning i cant 
reference my primary to a foreign key in another table and that's y I got 
this constraint error here??Am i right to say that??
Hope to get some help real soon...thanks in advance =)


A desc of my table:tutor
+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra  |
+---+--+--+-+-++
| tutor_id  | int(11)  |  | PRI | NULL| auto_increment |
| tutor_name| varchar(255) |  | | ||
| tutor_contact | varchar(12)  |  | | ||
| tutor_email   | varchar(255) |  | | ||
| tutor_profile | text |  | | ||
+---+--+--+-+-++

Irin.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Constraint Violation when INSERT

2003-12-09 Thread irinchiang


Hi all, 

I got the error  Constraint Violation  when I did an INSERT .
Gone thru the code umpteen times but to no avail..Wondering where my error 
was??...Below is a snip of the block of code:


?
$dsn = mysql://root:[EMAIL PROTECTED]/tablename;

$db = DB::connect ($dsn);
   if (DB::isError ($db))
   die ($db-getMessage());


//create variables ready to go into DB

$tutor_name = $db-quote($_POST[tutor_name]);
$tutor_contact = $db-quote($_POST[tutor_contact]);
$tutor_email = $db-quote($_POST[tutor_email]);
$tutor_profile = $db-quote($_POST[tutor_profile]);


$sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,  
tutor_profile)
VALUES ($tutor_name,$tutor_contact,$tutor_email,$tutor_profile);


$result = $db-query($sql);
if( DB::isError($result) ) {
die ($result-getMessage());
}
?

---
Everything was fine and the INSERT works, user input was insert into the 
database successful using the same block of code but the next thing i know I 
got this error anyone know watz the proz here???
Hope to get some help soon. Thanks in advance=)

Irin.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constraint Violation when INSERT

2003-12-09 Thread Martin Towell
 Hi all, 
 
 I got the error  Constraint Violation  when I did an INSERT .
 Gone thru the code umpteen times but to no avail..Wondering 
 where my error 
 was??...Below is a snip of the block of code:
 
 
 ?
 $dsn = mysql://root:[EMAIL PROTECTED]/tablename;
 
 $db = DB::connect ($dsn);
if (DB::isError ($db))
die ($db-getMessage());
 
 
 //create variables ready to go into DB
 
 $tutor_name = $db-quote($_POST[tutor_name]);
 $tutor_contact = $db-quote($_POST[tutor_contact]);
 $tutor_email = $db-quote($_POST[tutor_email]);
 $tutor_profile = $db-quote($_POST[tutor_profile]);
 
 
 $sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,  
 tutor_profile)
 VALUES 
 ($tutor_name,$tutor_contact,$tutor_email,$tutor_profile);
 
 
 $result = $db-query($sql);
 if( DB::isError($result) ) {
 die ($result-getMessage());
 }
 ?
 
 --
 -
 Everything was fine and the INSERT works, user input was 
 insert into the 
 database successful using the same block of code but the next 
 thing i know I 
 got this error anyone know watz the proz here???
 Hope to get some help soon. Thanks in advance=)
 
 Irin.


Don't you need to quote your strings?

$sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,  
tutor_profile)
VALUES
('$tutor_name','$tutor_contact','$tutor_email','$tutor_profile');

Martin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constraint Violation when INSERT

2003-12-09 Thread irinchiang


 Hi all, 
 
 I got the error  Constraint Violation  when I did an INSERT . 
 Gone thru the code umpteen times but to no avail..Wondering 
 where my error 
 was??...Below is a snip of the block of code: 
 
  
 ? 
 $dsn = mysql://root:[EMAIL PROTECTED]/tablename; 
 
 $db = DB::connect ($dsn); 
if (DB::isError ($db)) 
die ($db-getMessage()); 
 
 
 //create variables ready to go into DB 
 
 $tutor_name = $db-quote($_POST[tutor_name]); 
 $tutor_contact = $db-quote($_POST[tutor_contact]); 
 $tutor_email = $db-quote($_POST[tutor_email]); 
 $tutor_profile = $db-quote($_POST[tutor_profile]); 
 
 
 $sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,   
 tutor_profile) 
 VALUES 
 ($tutor_name,$tutor_contact,$tutor_email,$tutor_profile); 
 
 
 $result = $db-query($sql); 
 if( DB::isError($result) ) { 
 die ($result-getMessage()); 
 } 
 ? 
 
 -- 
 - 
 Everything was fine and the INSERT works, user input was 
 insert into the 
 database successful using the same block of code but the next 
 thing i know I 
 got this error anyone know watz the proz here??? 
 Hope to get some help soon. Thanks in advance=) 
 
 Irin. 


Don't you need to quote your strings? 

$sql = INSERT INTO tutor (tutor_name, tutor_contact, tutor_email,   
tutor_profile) 
VALUES 
('$tutor_name','$tutor_contact','$tutor_email','$tutor_profile'); 

Martin 

--

Yes, I actually quoted my string at the beginning but whenever i do 
an INSERT it actually insert a NULL value into the fields...why is this 
so???So I try not to quote the strings but I got a Contraints Violation 
errorWhat could be the problem??


--
Hope to get some help soon. All help are greatly appreciated.



Irin.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php