[SOLVED] Why this thing is so difficult in PHP
Posted 24 April 2006 - 11:55 AM
Here is my code:
$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.
$sql = "select * from tbl_wagest";
$result = mysql_query($sql);
$numrows = @mysql_num_rows($result);
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?
Posted 24 April 2006 - 12:10 PM
You should always use the "or die" clause an any mysql function, especially when you're debugging code. Use something like:
<?php $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.
Posted 24 April 2006 - 12:59 PM
Many thanks man!!!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users