Re: PHP/mySQL and INSERT statements

From: Date: Tue, 28 Aug 2001 07:28:58 +0000
Subject: Re: PHP/mySQL and INSERT statements
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-11882@lists.php.net to get a copy of this message
on 8/27/01 11:32 PM, Pyran Firebrand at pyranf@hotmail.com wrote: > $query = "INSERT INTO rants VALUES (1, '$date', '$type', > '$title', > '$text')"; > mysql_db_query($query, $db_link) or die ("<br>Problem!"); > } You should probably be specifying the database before the $query. By the way, use of the mysql_db_query function is now deprecated. You may wish to try: mysql_select_db($database_name,$db_link); mysql_query($query,$db_link); > When I try to execute this, it doesn't add anything into the database, and > prints out "Problem!". I have absolutely no idea why. Can someone give me > some direction here? I would be eternally grateful for it. The first step would be to echo the query and take a look at exactly what you're asking the mysql server to do. $query = "INSERT INTO rants VALUES (1, '$date', '$type', '$title', '$text')"; echo $query; exit; If the query looks OK, you should try it via the command line mysql client program to see what errors are reported. The errors from the command line are generally more descriptive than those from PHP. Another thing to try is instead of dying with "Problem!", try exiting with mysql_error and/or mysql_errno, that is: echo mysql_errno() , ': ' , mysql_error() , '<BR>'; HTH. Sincerely, Paul Burney ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Paul Burney Webmaster && Open Source Developer UCLA -> GSE&IS -> ETU (310) 825-8365 <webmaster@gseis.ucla.edu> <http://www.gseis.ucla.edu/> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

« previous php.db (#11882) next »