Jump to content

Problem passing variables from mysql populated form menu


Recommended Posts

Hi,

 

I'm trying to pass a variable from a form menu to another page.  The menu items have been populated via an sql query to a mysql database.  The query works as the drop down menu displays all the tutor names.  The problem is that when I select a surname, the variable is not passed, but rather it takes the default value of 'select'. 

 

The code below shows I also try to pass hidden variables (gained from the earlier sql query) and these are passing over to the next page fine.  I can't see why the value of the menu item is not passing.

 

Cheers for any help with this - it's driving me nuts..!

 

Pip

 

Coding from page 1

// Code to connect to database - this is working fine
// Perform sql query to get various details from database - again working fine

echo "Use the drop down menu to select a tutor";

echo "<form method = 'post' action = 'page.php'>"
echo "<select name='id'>";
echo "<option value = 'select'>Select Tutor</option>

// Perform sql query to get specific tutor details from database - working fine

while ($row='mysql_fetch_array($result))
{
     $id = $row["id"];
     $surname = $row["surname"];
     echo "<option value = ' " . $id . " ' >" . $surname . "</option>";
}
echo "</select>";
echo "<input type='hidden' name='school' value = '$school' />
echo "<input type='hidden' name='code' value = '$code' />
echo "input type = 'image' src='../images/submit.png' />
echo "</form>

 

Coding from beginning of page 2 - showing whether variables have passed

$id = $_POST['id'];
$school = $_POST['school'];
$code = $POST['code'];
echo "id is $id<br>school is $school<br>code is $code.";

 

When you do a "view source" of the form page in your browser, what do you get for the <option values?

 

If the form is correct, you would need to post your whole actual form processing code if you want someone to determine what it is doing that is causing the problem.

 

Best guess, you have an if() statement that is assigning the value 'select' to the variable instead of comparing the variable with the value 'select' (i.e. using one = (an assignment operator) instead of two == (an equal comparison operator.)

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.