Jump to content


This topic is now archived and is closed to further replies.


[SOLVED] Why this thing is so difficult in PHP

Recommended Posts

I am new php user and trying to display records from mysql. This thing is so simple in ASP but here it is like a pain in the ass. I tried running it on LOCALHOST (my own computer) and HOSTING SERVER (where my site is hosted) but no luck. Localhost runs PHP version 5.1.1 and Hosting Server runs 4.4.2.

Here is my code:

[b]$username = "root";
$password = "root";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("<BR><font face=arial size=3 color=red>Unable to connect to database. Please try again later.</font>");


The above connection works and I am able to connect to the database on both LOCALHOST and HOSTING SERVER.

[b]$sql = "select * from tbl_wagest";
$result = mysql_query($sql);

if ($result)
echo "true";
echo "false";

$numrows = @mysql_num_rows($result);
echo $numrows;[/b]

Now the above piece of code doesn't print $numrows and the IF condition says FALSE which I think means there are no records. But the records are there in the table infact more than 100 but it doesn't print $numrows.

This is happening both LOCALHOST and HOSTING SERVER. What am I doing wrong? :(

Share this post

Link to post
Share on other sites
The "false" return from the mysql_query() functions usually means there is a problem with the query's syntax not that there are no rows.

You should always use the "or die" clause an any mysql function, especially when you're debugging code. Use something like:
$result = mysql_query($sql) or die('There was a problem with the query: <span style="color:red">' . $sql . '<br>' . mysql_error());

Put the "or die" clause in and see what error is displayed. That should give you a hint as to want is wrong.


Share this post

Link to post
Share on other sites


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.