List:General Discussion« Previous MessageNext Message »
From:PJ Date:February 26 2009 6:16pm
Subject:Re: [PHP] catch the error
View as plain text  
Ashley Sheridan wrote:
> On Thu, 2009-02-26 at 12:28 -0500, PJ wrote:
>> What is wrond with this file? same identical insert works from console
>> but not from this file :-(
>>
>> <html>
>> <head>
>> <title>Untitled</title>
>> </head>
>>
>> <body>
>> <?
>> //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();
>> }
>> ?>
>>
>> </body>
>> </html>
>>
>> Seems to be good to print out the error message, but that's all. db not
>> written.
>>
>> -- 
>>
>> Phil Jourdan --- pj@stripped
>> http://www.ptahhotep.com
>> http://www.chiccantine.com
>>
>>
> I'd say it was the way you are trying to connect to your database. This
> is how it's done:
>
> $db_host = 'localhost';
> $db_user = 'root';
> $db_password = '';
> $db_name = 'database_name';
>
> $db_connect = mysql_connect($db_host, $db_user, $db_pass);
> $db_select = mysql_select_db($db_name, $db_connect);
>
> You see, first you have to cerate a connection to the database server,
> then you have to select your database on that connection. In your
> example, 'biggie' is the name of a server where your database resides,
> and 'test', well, what can I say? This 4th parameter should be a boolean
> indicating whether or not a new connection should be made upon
> successive calls to mysql_connect.
>
>
> Ash
> www.ashleysheridan.co.uk
>
>
OK, I see my error...understood and fixed... but it still does not work.
But I did have an error - the include was wrong - missing ../
Something is till amiss... the include configuration works, this does not?
Why?

<?
//include ("../lib/db1.php");    // Connect to database

$db_host = 'biggie';
$db_user = 'myuser';
$db_pass = 'my_pwd';
$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@stripped
http://www.ptahhotep.com
http://www.chiccantine.com
Thread
Re: [PHP] catch the errorPJ26 Feb