Addin records to msql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
birchtrees
Forum Newbie
Posts: 3
Joined: Thu Sep 05, 2002 2:29 pm

Addin records to msql

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
birchtrees
Forum Newbie
Posts: 3
Joined: Thu Sep 05, 2002 2:29 pm

Problem solved

Post by birchtrees »

Thanks for your help. It's working perfectly.
Post Reply