Jump to content

I think I'm going cazy!


izbryte

Recommended Posts

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

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

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

Fixed else statements to elseif  ;D

 

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

also one last error i see but  make that error all text it isnt going to show a variable that isnt set. :P

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.