Re: catch the error

From: Date: Thu, 26 Feb 2009 18:22:09 +0000
Subject: Re: catch the error
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-288846@lists.php.net to get a copy of this message
Ricardo Dias Marques wrote: > Hi PJ, > > On Thu, Feb 26, 2009 at 17:28, PJ <af.gourmet@videotron.ca> wrote: > > >> What is wrond with this file? same identical insert works from console >> but not from this file :-( >> >> [snip] >> >> <? >> //include ("lib/db1.php"); // Connect to database >> mysql_connect('biggie', 'user', 'password', >> 'test'); >> $sql1 = "INSERT INTO example (name, age) VALUES ('Joe Blow', >> '69')"; >> $result1 = mysql_query($sql1,$db); >> if (!$result1) { >> echo("<P>Error performing 1st query: " . >> mysql_error() . "</P>"); >> exit(); >> } >> ?> >> > > I haven't coded in PHP for a long time, but I think that your problem > is in this line: > > $result1 = mysql_query($sql1,$db); > > Up to that point, $db (that should point to a database link > identifier) is not defined. You probably want to assign the > "mysql_connect" result to that $db variable. > > > So, I think that you will solve your problem by changing your > "mysql_connect" line FROM the current form: > > mysql_connect('biggie', 'user', 'password', 'test'); > > .. TO this one: > > $db = mysql_connect('biggie', 'user', 'password', > 'test'); > > > Am I right? Partly. I had an error in the location of the include. Ashley corrected the rest but it only works with the include. Not as whown below <? //include ("../lib/db1.php"); // Connect to database $db_host = 'biggie'; $db_user = 'root'; $db_pass = 'gugus@#$'; $db_name = 'biblane'; $db_connect = mysql_connect($db_host, $db_user, $db_pass); $db_select = mysql_select_db($db_name, $db_connect); $sql1 = "INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75')"; $result1 = mysql_query($sql1,$db); if (!$result1) { echo("<P>Error performing 1st query: " . mysql_error() . "</P>"); exit(); } ?> -- Phil Jourdan --- pj@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com

« previous php.general (#288846) next »