Jump to content

Recommended Posts

Hi, I'm a php newbie and I'm stuck.

 

I have a form with a dynamic field (a list of available training courses, pulled from mysql, in a <select> dropdown menu). How do I deal with this in the handling script?  I want the form data to go into a different database along with the applicant's details etc, email the applicant with confirmation of receipt etc and when setting the variables, $_POST[$variable] doesn't work.

 

Here is the code from the form

 

$results=mysql_query("select courses_available from courses_database")

or die(mysql_error());

 

echo "<select name=\"course applied for\">\n";

while($row=mysql_fetch_array($results)){

$course=$row[course];

echo "<option value=\"$course\">$course";

echo "</option>\n";

}

echo "</select>\n";

 

Here is the list of variables in the handling script so you can see what I'm getting at

 

$name=$_POST['name'];

$address1=$_POST['address1'];

$address2=$_POST['address2'];

$address3=$_POST['address3'];

$email=$_POST['email'];

$phone=$_POST['phone'];

$dob=$_POST['dob'];

$experience=$_POST['experience'];

$course_name=$_POST['$course'];

 

Can anyone help? Thanks in advance!  :D

Link to comment
https://forums.phpfreaks.com/topic/191899-_postvariable/
Share on other sites

echo "<select name=\"course applied for\">\n";

 

Should be:

echo "<select name=\"course_applied\">\n";

 

As spaces cause some funky issues. Then to call that:

 

$course_applied = $_POST['course_applied'];

 

A side note, you use "$course" inside of single quotes, that is taken literally and not evaluated to the value. Either encase it in double quotes or remove the quotes all together.

 

Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/191899-_postvariable/#findComment-1011477
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.