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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.