Page 1 of 1

Cannot insert into database, sql OK!

Posted: Thu Apr 08, 2004 9:11 am
by Ppieter
Hi there,

I have a problem inserting into all of my databases. Think there must be a problem with permissions on my suse 9, mysql 4 apache2 and php 4 server. I've tried to figure out for the last couple of days, but......
Even the simplest of SQL won't work and i don't get an error:

$query = "INSERT INTO tbl_table(naam) VALUES('KAREL')";
$result = mysql_query ($query);

Any ideas anyone?

Posted: Thu Apr 08, 2004 9:15 am
by JayBird
i don't think you should use the $result. You don't need to assign it, just execute it like this. Only SELECT,SHOW,EXPLAIN or DESCRIBE statements return a resource identifier.

Code: Select all

$query = "INSERT INTO tbl_table(naam) VALUES('KAREL')"; 
mysql_query ($query);
Mark

Posted: Thu Apr 08, 2004 9:16 am
by twigletmac
Also add error handling to the query call, just in case MySQL's not happy:

Code: Select all

mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');
Mac

Posted: Thu Apr 08, 2004 9:48 am
by Wayne
are you connecting to localhost or the ip address? do you have the correct permissions setup in mysql? error handling like mac suggested is always a good idea!