Jump to content

Please WHO can help me?


Gladstone365

Recommended Posts

 

I have this code that i am learning that I got from a PHP tut.

 

When I write the code up to a certain point I get a favorable result. When I now add the code to get the data from my database i get an error message. Please tell me what should I be doing or not doing? Here is the code:-

 

<?PHP

 

$user_name = "root";

$password = "";

//$database="checking";

$database = "address_book";

$server = "127.0.0.1";

 

/*mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database);

*/

$db_handle = mysql_connect($server, $user_name, $password);

 

$db_found = mysql_select_db($database, $db_handle);

 

print "Connection to the Server opened.";

 

if ($db_found) {

 

print "Database Found";

mysql_close($db_handle);

}

else {

 

print "Database NOT Found";

}

?>

The code above gives me a favorable result. When I run the code with EASYPHP I get the following result

Connection to the Server opened.Database Found

 

*** This is where the problem now comes up. When I add this code i get an error message.

 

[while ($db_field = mysql_fetch_assoc($result)) {

print $db_field['ID'] . "<BR>";

print $db_field['First_Name'] . "<BR>";

print $db_field['Surname'] . "<BR>";

print $db_field['Address'] . "<BR>";

}

I get the following error message[Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\EasyPHP 2.0b1\www\docs\prac\webdesign\connect_test.php on line 25

 

Following is the full script and code that gives me the error message above

 

 

 

<?PHP

 

$user_name = "root";

$password = "";

//$database=checking";

$database = "testdb";

$server = "127.0.0.1";

 

/*mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database);

*/

$db_handle = mysql_connect($server, $user_name, $password);

 

$db_found = mysql_select_db($database, $db_handle);

 

print "Connection to the Server opened.";

 

if ($db_found) {

 

print "Database Found";

//

$SQL = "SELECT * FROM tb_address_book";

$result = mysql_query($SQL);

 

while ($db_field = mysql_fetch_assoc($result)) {

print $db_field['ID] . "<BR>";

print $db_field['First_Name'] . "<BR>";

print $db_field['Surname'] . "<BR>";

print $db_field['Address'] . "<BR>";

}

mysql_close($db_handle);

 

}

else {

 

print "Database NOT Found";

}

?>

I now get the following message

 

[Connection to the Server opened.Database Found

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\EasyPHP 2.0b1\www\docs\prac\webdesign\connect_test.php on line 25

 

Please who can help me? I am just learning PHP. Thanks.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.