horrible problem carrying over a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

horrible problem carrying over a variable

Post by Fusioned »

Hi guys,

I'm working on a "shopping cart" like system for around campus and the make a long story short, people are presented with a drop down option menu for their school. The school name is there but the value for each one is a number (1, 2, 3...), the number is known as the variable $school.

So then they click "Next" after choosing their school. Only problem is, the variable wont carry over no matter what unless I make it a set variable by typing somewhere in the code:

Code: Select all

$school = &quote;1&quote;
or whatever

Here's the code below for index.php with the drop down menu for the schools:

Code: Select all

What school are you ordering from?<BR>
<?php

echo &quote;
<FORM ACTION='university.php' METHOD=POST>
<select name='school'>
	<option value='1'>Drexel University
	<option value='2'>University of Pennsylvania
	<option value='3'>Temple University

</select><BR><BR>
<INPUT TYPE='SUBMIT' NAME='SUBMIT' VALUE='>>Next'>
</FORM>
&quote;;

$items = &quote;0&quote;;
?>
and then when you click NEXT it takes you to university.php:

Code: Select all

<?php


///Connection Stuff
$host = &quote;localhost&quote;;
$user = &quote;myuser&quote;;
$pass = &quote;pass&quote;;
$db = &quote;food&quote;;
$table = &quote;places&quote;;
mysql_connect ($host,$user,$pass) or die ( mysql_error ()); 
mysql_select_db ($db)or die ( mysql_error ()); 

$query = &quote;select places.* from schools, places where places.pid = '$school' AND  places.pid = schools.pid&quote;;
$result = mysql_query($query)
or die(mysql_error());
?>
<table cellspacing=&quote;2&quote; cellpadding=&quote;2&quote;>
<tr> <td>Name</td> <td>Address</td> <td>Hours</td></tr>
<?php
while($row = mysql_fetch_array( $result )) {
echo &quote;<tr><td>&quote;;
echo $rowї'name'];
echo &quote;</td><td>&quote;;
echo $rowї'address'];
echo &quote;</td><td>&quote;;
echo $rowї'hours'];
echo &quote;</td></tr>&quote;;
}
echo &quote;</table>&quote;;

?>


Your school is:<?php echo &quote;<b>$school</b>\n&quote;; ?> (<a href=&quote;index.php&quote;>change</a>)<BR>
Please choose from a list of stores/restaurants below:<BR>
<?php
echo &quote;
<form action='store.php?school=$myschool&store=$store' method=POST>
<select name='store'>

	<option value='Wawa'>Wawa</option>
	<option value='CVS'>CVS</option>
	<option value='McDonalds'>McDonalds</option>
	<option value='7-Eleven'>7-Eleven</option>
	<option value='The Fresh Grocer'>The Fresh Grocer</option>
	<option value='Ben & Jerrys'>Ben & Jerrys</option>
	<option value='Evans Varsity Pizza'>Evans Varsity Pizza</option>
	<option value='Taco Lous'>Taco Lous Restaurante/Cart</option>
	<option value='Custom'>Custom Orders</option>

</select><BR><BR>
<input type='submit' name='submit' value='>>Next'>&quote;;


?>
This is KILLING ME. I've literally been spending hours each day trying to find out why it won't even display the variable. It's killing me! Any help or suggestions are much appreciated from the bottom of my heart! Argh! :x

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

It's a bit hard to read, use

Code: Select all

tags.

try $_POST["school"]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

replace

Code: Select all

$query = "select places.* from schools, places where places.pid = '$school' AND  places.pid = schools.pid";
with

Code: Select all

$query = "select places.* from schools, places where places.pid = '".$_POST['$school']."' AND  places.pid = schools.pid";
It is because register globals is set to OFF which is by default. Please read http://php.net/register_globals for more information.
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

Post by Fusioned »

Not working. Im testing the code off my own server though, so if theres anything i can do on the server side, lemme know. I cant believe $_POST["school"] didn't work.

In fact, using the URL wont even work:

http://10.0.1.6/blahblah/university.php?school=1

Doesn't work.
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

Post by Fusioned »

AHHH. Had to extract the variable. Wow. Thanks so much guys. This forum is a godsend. :D
Post Reply