Page 1 of 1

Addin records to msql

Posted: Thu Sep 05, 2002 2:29 pm
by birchtrees
Hello,
Could someone please explain how I can Update a data base with this code

$link = mysql_connect("localhost", "pelicandecal", "pelsto");
mysql_select_db("pelicandecal", $link);
$result = mysql_query("UPDATE orders SET comp = '$compa', item1 = '$itema', item2 = '$itemb', item2 = '$itemc'
WHERE code = 1", $link);



but I can't Insert a new record with this code

$link = mysql_connect("localhost", "pelicandecal", "pelsto");
mysql_select_db("pelicandecal", $link);
$result = mysql_query ("INSERT INTO orders (code, comp, item1, item2, item3)
VALUES (Null, '$compa', '$itema','$itemb','$itemc' )",$link);


Thank-you very much

Posted: Thu Sep 05, 2002 2:43 pm
by twigletmac
Try using mysql_error() to trap any problems printing out the SQL statement might help you debug too:

Code: Select all

$link = mysql_connect('localhost', 'pelicandecal', 'pelsto') or die(mysql_error()); 
mysql_select_db('pelicandecal') or die(mysql_error());
$sql = "INSERT INTO orders (code, comp, item1, item2, item3) VALUES (NULL, '$compa', '$itema','$itemb','$itemc')";
echo $sql;
mysql_query ($sql) or die(mysql_error());
Mac

Problem solved

Posted: Thu Sep 05, 2002 8:53 pm
by birchtrees
Thanks for your help. It's working perfectly.