i’m trying to write info into a db table and it’s not working at all. i’ve been messing with it for hours. maybe if someone looks at the code they’ll see something i missed.
my logic is it connects to the db server, opens database mydb, goes to table mod, and writes to id, fname, and lname, then closes the connection.
also, id is set to auto_increment. from what i can tell it should work but it doesn’t.
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb', $con);
//assign
$query = "INSERT INTO 'mod' (id, fname, lname) VALUES ('', 'bill', 'smith')";
if (!$query){
dir ("Unable to create the record:" . mysql_error());
exit;
}
mysql_query($query);
mysql_close($con);
you are making miskate in referencing the tablename. It should be
`mod` instead of ‘mod’. i.e ` [backtick] not ‘[single quote].and second error is with your die statement…instead of dir it should be die….
Next you can also skip inserting value for id field which is autoincreament
so it can be