Cannot insert into database, sql OK!

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
Ppieter
Forum Newbie
Posts: 1
Joined: Thu Apr 08, 2004 9:11 am

Cannot insert into database, sql OK!

Post 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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Last edited by JayBird on Thu Apr 08, 2004 9:20 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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!
Post Reply