ali_kiyani Posted April 24, 2006 Share Posted April 24, 2006 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>");mysql_select_db("MyDB",$dbh);[/b]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";else 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? :( Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 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:[code]<?php$result = mysql_query($sql) or die('There was a problem with the query: <span style="color:red">' . $sql . '<br>' . mysql_error());?>[/code]Put the "or die" clause in and see what error is displayed. That should give you a hint as to want is wrong.Ken Quote Link to comment Share on other sites More sharing options...
ali_kiyani Posted April 24, 2006 Author Share Posted April 24, 2006 aha!!!! that solved my problem.Many thanks man!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.