For example if I have the following:
Ford Saab Mercedes AudiHow do I output what the user selects?
For example if I have the following:
Ford Saab Mercedes AudiHow do I output what the user selects?
You are missing tags, and a submit button. Here is the correct html code:
[code]
Ford Saab Mercedes Audi [/code]And here is the code of submit.php script, where you can see how to output user selection in html form:
[php]<?php
if(isset($_POST[‘make’]) and $_POST[‘make’]!=’’){
echo $_POST[‘make’];
}
else{
echo ‘Nothing selected’;
}
?>[/php]
Thank you for the quick response!
So if I’m understanding this right, then the user’s selection is stored you might say in the “make” index?
Then it is called back to using the $_POST in the php section?
I need to store a selection of a menu into a variable so I can use it to reference a line in a MySql database.
Yes, if your form method is ‘post’ - all the submitted values will be passed to php script via global array $_POST.
If method is ‘get’ (for example: http://www.mysite.com/index.php?make=audi) then, all the values are passed via $_GET array. In both cases you can use $_REQUEST - this will store both ‘post’ and ‘get’ variables.
So would this work?
I would have:
$make=$_POST[“make”];
//connect code and other stuff
$result2=mysql_query(“SELECT * FROM machine
WHERE Model
=’$make’”);
this would reference my sql table based on the selection made in the list?
Yes, this will work. But I would also recommend to use mysql_real_escape_string() function, to escape any special characters:
[php]$result2=mysql_query(“SELECT * FROM machine
WHERE Model
=’”.mysql_real_escape_string($make)."’");[/php]
Even that you have no such characters in your ‘make’ list, someone could try sql injection with your code, and the mysql_real_escape_string() function will prevent such attempts.
Thanks you all! I will let you know if I figure it out today!
Fixed! Thanks for your help!