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!!! Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/ 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. Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/#findComment-506040 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 Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/#findComment-506050 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. Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/#findComment-506053 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. ?> Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/#findComment-506056 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 Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/#findComment-506067 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. ?> Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/#findComment-506071 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. ?> Link to comment https://forums.phpfreaks.com/topic/98900-i-think-im-going-cazy/#findComment-506088 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.