RE: [PHP] Constraint Violation when INSERT

From: Date: Wed, 10 Dec 2003 05:46:46 +0000
Subject: RE: [PHP] Constraint Violation when INSERT
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-172318@lists.php.net to get a copy of this message
> 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:**********@localhost/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" error....What could be the problem>>?? ------------------------------------------------------------------------------ Hope to get some help soon. All help are greatly appreciated. Irin.

« previous php.general (#172318) next »