Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP results not showing up, what going on?

Status
Not open for further replies.

mygmat123

Technical User
Jun 28, 2004
56
US
<html>
<head>
<title> My first php page</title>

</head>

<body>

<h1>Firstdb PHP results</h1>



<?php

@ $db=mysql_pconnect('localhost','root','');

if (!$db)
{
echo 'Error could not connect to database';
exit;
}

//check if connection works
if (DB::iserror($db))
{
echo $db->getmessage();
exit;
}

mysql_select_db('firstdb');

$query = "SELECT * FROM table1";
$result = mysql_query($query);

$num_results = mysql_num_rows($result);

echo '<p>Number of records found: '.$num_results.'</p>';

?>


</body>

</html>
 
Are you getting any errors?


This line is incorrect:

@ $db=mysql_pconnect('localhost','root','');

The "@" error-supression operator should appear just before the function invocation. I strongly recommend against using "@", as it can supress error messages you need to see.

Also, not having a login for the MySQL root user is a very bad idea.



This segment:
if (DB::iserror($db))
{
echo $db->getmessage();
exit;
}

Looks more like perl code than PHP code. But I don't see a "DB" namespace anywhere. Also, at this point in your code $db will not be an object, but a resource handle -- basically an integer. You can't use the "->" object-reference operator here.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thank you, I'm just starting learning this stuff. I'll try your recommendations. The mysql is on my local LAN at home so no one has access but me. That's why the root is the way it is.

Thanks I'll see if I can improve it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top