Inderjeet Posted October 1, 2007 Share Posted October 1, 2007 Can anyone tell me the problem with this code I am a newbie. <?php $link=mysql_connect("localhost","root",""); if(!$link) {die("couldn't connect to database".mysql_error());} mysql_select_db("domains"); or die("Could not select the database".mysql_error()) $result = mysql_query("SELECT * FROM test_acc"); if ( empty($result) ) die("SELECT problem. Query: $sql Reason: ".mysql_error()." Page: $page while getting customer data. Ending process. Please tell the administrator about this at $webmaster_email attaching this error missage."); echo "<table border='2'>"; echo"<tr> <th>User ID</th> </tr>"; while( $row = mysql_fetch_array( $result)) { echo "<tr><td>"; echo $row['domain'] ; echo"</td>"; echo "</tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/ Share on other sites More sharing options...
trq Posted October 1, 2007 Share Posted October 1, 2007 Are you getting any errors? What are they? Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/#findComment-359052 Share on other sites More sharing options...
Inderjeet Posted October 1, 2007 Author Share Posted October 1, 2007 no I am not getting any errors I have rechecked this code many times but it is not showing up any output db name is correct table name is correct Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/#findComment-359054 Share on other sites More sharing options...
php_dave Posted October 1, 2007 Share Posted October 1, 2007 Is this the whole script you are showing us.. die("SELECT problem. Query: $sql Reason: ".mysql_error()." Page: $page while getting customer data. Ending process. Please tell the administrator about this at $webmaster_email attaching this error missage."); I cant see the red vars given any values in your script... maybe why your die message is not showing anything. Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/#findComment-359058 Share on other sites More sharing options...
Inderjeet Posted October 1, 2007 Author Share Posted October 1, 2007 Is this the whole script you are showing us.. die("SELECT problem. Query: $sql Reason: ".mysql_error()." Page: $page while getting customer data. Ending process. Please tell the administrator about this at $webmaster_email attaching this error missage."); I cant see the red vars given any values in your script... maybe why your die message is not showing anything. If u remove the above script also then also it is not showing any output. Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/#findComment-359067 Share on other sites More sharing options...
trq Posted October 1, 2007 Share Posted October 1, 2007 Try this instead and let us know what you get. <?php mysql_connect("localhost","root","") of die("couldn't connect to database".mysql_error()); mysql_select_db("domains") or die("Could not select the database".mysql_error()) $sql = "SELECT * FROM test_acc"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { echo "<table border='2'>"; echo"<tr><th>User ID</th></tr>"; while ($row = mysql_fetch_assoc( $result)) { echo "<tr><td>"; echo $row['domain'] ; echo"</td>"; echo "</tr>"; } echo "</table>"; } else { echo "No results found"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> ps: This is probably a better example of the logic for a SELECT query. Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/#findComment-359074 Share on other sites More sharing options...
php_dave Posted October 1, 2007 Share Posted October 1, 2007 Which suggests you are not making a connection to the db successfully - try just die("DB ERROR : ".mysql_error(); And see if that returns anything of use... Do you have error messages turned on in you php.ini file? check out the error_reporting() function to do something like this // This is the default value set in php.ini error_reporting(E_ALL ^ E_NOTICE); Just in case it is not set in you PHP.INI HTH Dave Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/#findComment-359076 Share on other sites More sharing options...
thedarkwinter Posted October 1, 2007 Share Posted October 1, 2007 Hi you have a syntax error near the beggining to do with the semi-colon <?php //.... mysql_select_db("domains"); // should not be here or die("Could not select the database".mysql_error()) // should be here should be <?php //.... mysql_select_db("domains") or die("Could not select the database".mysql_error()); as php_dave said, turn on error reporting and you will see this cheers, tdw Quote Link to comment https://forums.phpfreaks.com/topic/71361-can-anyone-debug-this-code/#findComment-359132 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.