suttercain Posted February 2, 2007 Share Posted February 2, 2007 Hi Everyone I am trying to just display a simple list using PHP via MySQL. Nothing fancy, no css at this point just a list. <?php $username = "iiiii"; $password = "iiiiii"; $dbname = "iiiiii"; $hostname = "localghost"; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); //Make the Query $query = "SELECT * FROM 1997data ORDER BY MFR"; $result = @mysql_query ($query)or die(mysql_error());//Run the Query if ($result {//If it ran okay display the record //Table header echo '<table align="center" cellspacing="0" cellpadding ="5"> <tr><td align="left"><b>Manufacture</b></td></tr> '; //Fetch and Print while ($row = mysql_fetch_array (result, MYSQL_ASSOC)) { echo '<tr><td align="left">' . $row['mfr'] . '</td></tr> '; } echo '</table>'; mysql_free_result ($result);//Free up resources } else { //if it did not run okay echo '<p>' . mysql_error() . '<br/><br/>Query; ' . $query . '</p>'; //Debugging } mysql_close(); //Close connection ?> When I go to view the page, list.php, I don't get an error reports, just the white page. Blank. Nothingness.... the abyss. Can someone tell me what I am doing wrong? Thanks in adavance! Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2007 Share Posted February 2, 2007 if ($result { needs to be if ($result){/ Quote Link to comment Share on other sites More sharing options...
suttercain Posted February 2, 2007 Author Share Posted February 2, 2007 Hi Jesirose, Thanks for the reply. I made the change if ($result){ But instead of the white "nothing" like from The Never Ending Story, I now get the following error... Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) I know it's right there in front of me, but I can't get it... Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2007 Share Posted February 2, 2007 Well now the page has compiled. You have "localghost" I assume you meant "localhost" Quote Link to comment Share on other sites More sharing options...
suttercain Posted February 2, 2007 Author Share Posted February 2, 2007 Yes, I changed the login info.... It's connected okay. The $username = "iiiii"; $password = "iiiiii"; $dbname = "iiiiii"; $hostname = "localghost"; Are 2 legit 2 quit. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2007 Share Posted February 2, 2007 That made no sense whatsoever, but as you said it's connected, it seems the problem has been fixed. Quote Link to comment Share on other sites More sharing options...
Snooble Posted February 2, 2007 Share Posted February 2, 2007 MAKE SURE it is connected if you are still recieving the error. Snooble Quote Link to comment Share on other sites More sharing options...
suttercain Posted February 2, 2007 Author Share Posted February 2, 2007 The login information is all correct. I changed it in the above code for security reasons. My question is, how come the list isn't being displayed on the page. I am selecting it, identifying the table and sort order. But I get either the blank page or the error "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" I have done the list display in the past but I have been unable to achieve this over the past 2 days. Shannon Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2007 Share Posted February 2, 2007 Is your mysql actually localhost? It's a connection error, so you need to verify your connection information. We can't help with that. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 2, 2007 Share Posted February 2, 2007 Your problem lies here: while ($row = mysql_fetch_array (result, MYSQL_ASSOC)) { should be: while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { Gotta make sure you reference the right 'result'. Quote Link to comment Share on other sites More sharing options...
stu10576 Posted February 3, 2007 Share Posted February 3, 2007 check on this //**the variable $dbname doesn't match with the $dbName <?php $username = "iiiii"; $password = "iiiiii"; //**the variable $dbname doesn't match with the $dbName below $dbname = "iiiiii"; $hostname = "localghost"; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); //$dbName doesn't match with the $dbname above $db = mysql_select_db($dbName, $conn) or die(mysql_error()); //Make the Query $query = "SELECT * FROM 1997data ORDER BY MFR"; $result = @mysql_query ($query)or die(mysql_error());//Run the Query if ($result {//If it ran okay display the record //Table header echo '<table align="center" cellspacing="0" cellpadding ="5"> <tr><td align="left"><b>Manufacture</b></td></tr> '; //Fetch and Print while ($row = mysql_fetch_array (result, MYSQL_ASSOC)) { echo '<tr><td align="left">' . $row['mfr'] . '</td></tr> '; } echo '</table>'; mysql_free_result ($result);//Free up resources } else { //if it did not run okay echo '<p>' . mysql_error() . '<br/><br/>Query; ' . $query . '</p>'; //Debugging } mysql_close(); //Close connection ?> Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted February 3, 2007 Share Posted February 3, 2007 first problem i noticed with your sql if ($result {//If it ran okay display the record should be if ($result) {//If it ran okay display the record Second Problem //Fetch and Print while ($row = mysql_fetch_array (result, MYSQL_ASSOC)) { Should be while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { 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.