izbryte Posted March 31, 2008 Share Posted March 31, 2008 I have a login area that pulls up a store Id # which is sent in a hyperlink. So, for example the action of the login form is order.php and the hyperlink will show http://www.mysite.com/order.php?store_id=1. Then I have this script: <?php require "../db_conn.inc.php"; include_once ('header2.htm'); if (isset($_GET['store_id'])) { // Handle the form. $id = $_GET['store_id']; // Make the query. $query = "SELECT * FROM users WHERE store_id = '$id'"; $result = @mysql_query ($query); // Run the query. if ($result) { // If it ran OK, display the records. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<p>'.$row[store_id].'</p>'; } mysql_free_result ($result); // Free up the resources. } else { // If it did not run OK. echo '<p>The store could not be displayed due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>'; } mysql_close(); // Close the database connection. } else{ echo '<p>Problem getting $store_id id.</p>'; } include_once ('footer2.htm'); // Include the HTML footer. ?> At this point, all I want is to pull the store_id out of the database. What's happening is all I get now is a page showing only the header and footer. I Know the Db connect info is fine cuz it works on other pages. This seems like such an easy script! I'm ready to pull my hair out! HELP!!! Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted March 31, 2008 Share Posted March 31, 2008 What is with the @? $result = @mysql_query ($query); // Run the query. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2008 Share Posted March 31, 2008 remove the @ it supresses errors and put in this: <?php ini_set('error_reporting',E_ALL); ?> then tell me what you get Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 31, 2008 Share Posted March 31, 2008 the @ suppresses error messages $query = "SELECT `store_id` FROM `users` WHERE `store_id` = '$id'"; $result = @mysql_query ($query); // Run the query. if ($result) { // If it ran OK, display the records. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<p>'.$row['store_id'].'</p>'; } For one, don't use SELECT * when you only want 1 column from the DB. Wastes memory and execution time Another, your associative array keys need quotes around them, like any string. This might help. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 Fixed Code: <?php ini_set('error_reporting',EALL); require "../db_conn.inc.php"; include_once ('header2.htm'); if (isset($_GET['store_id'])) { // Handle the form. $id = $_GET['store_id']; // Make the query. $query = "SELECT * FROM users WHERE store_id = '$id'"; $result = mysql_query ($query); // Run the query. if ($result) { // If it ran OK, display the records. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<p>'.$row['store_id'].'</p>'; } mysql_free_result ($result); // Free up the resources. } else { // If it did not run OK. echo '<p>The store could not be displayed due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>'; } mysql_close(); // Close the database connection. } else{ echo '<p>Problem getting $store_id id.</p>'; } include_once ('footer2.htm'); // Include the HTML footer. ?> Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 You're still using SELECT *. You really should avoid pulling unneeded data from your database. It simple slows things down and increases chance of error Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 Fixed else statements to elseif also changed your SQL statement discomatt was right. <?php ini_set('error_reporting',E_ALL); require "../db_conn.inc.php"; include_once ('header2.htm'); if (isset($_GET['store_id'])) { // Handle the form. $id = $_GET['store_id']; // Make the query. $query = "SELECT store_id FROM users WHERE store_id = '$id'"; $result = mysql_query ($query); // Run the query. if ($result) { // If it ran OK, display the records. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<p>'.$row['store_id'].'</p>'; } mysql_free_result ($result); // Free up the resources. } elseif(!$result) { // If it did not run OK. echo '<p>The store could not be displayed due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>'; } mysql_close(); // Close the database connection. } elseif(!isset($_GET['store_id'])){ echo '<p>Problem getting $store_id id.</p>'; } include_once ('footer2.htm'); // Include the HTML footer. ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 also one last error i see but make that error all text it isnt going to show a variable that isnt set. <?php ini_set('error_reporting',E_ALL); require "../db_conn.inc.php"; include_once ('header2.htm'); if (isset($_GET['store_id'])) { // Handle the form. $id = $_GET['store_id']; // Make the query. $query = "SELECT store_id FROM users WHERE store_id = '$id'"; $result = mysql_query ($query); // Run the query. if ($result) { // If it ran OK, display the records. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<p>'.$row['store_id'].'</p>'; } mysql_free_result ($result); // Free up the resources. } elseif(!$result) { // If it did not run OK. echo '<p>The store could not be displayed due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>'; } mysql_close(); // Close the database connection. } elseif(!isset($_GET['store_id'])){ echo '<p>Problem getting store id.</p>'; } include_once ('footer2.htm'); // Include the HTML footer. ?> 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.