Forum Moderators: coopster

Message Too Old, No Replies

Using PHP Combo Box & Mysql

Help me programmers please as soon as possible

         

ahmadscript

12:35 am on Feb 11, 2005 (gmt 0)

10+ Year Member



i am new to php, mysql, & Apache but i achived the point where the all things allright and start to make my site until i faced the following problem:
i have tables in mysql
and i wanna users to use a combobox to enter the data in these tables and i am using php to achive this goal how to make the data entered into the combo box storied in the mysql table
and thank u in advance

Zipper

9:41 am on Feb 11, 2005 (gmt 0)

10+ Year Member



Welcome to Webmasterworld, Ahmad!

combo boxes are used to select data and not necessarily enter them. so could you please elaborate on what you're trying to achieve so that we could help you with it.. posting ur existing input fields might be a good idea..

ahmadscript

7:55 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Dear Zipper thank you for your time and interest

what i am doing is as follows:
i am making a database using mysql + php + apache
and i have a table in mysql that stores information like this:

Name + date_of_birth + Gender + Country + ... and so on

this table as i told u stores information about persons information who subscribe with my site and i want them to select Country and Gender from a combo box instead of writing this information in a text field
this is like hotmail or yahoo Registration form
thank you again

Zipper

4:23 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



in php working with combo boxes are no different than working with simple text boxes. meaning you do pretty much the same to get the values.. hope this example helps you understand how to get on with your script.

your html form:


<form action="process.php" method="POST">
Name: <input type="text" name="name" /><br />
DOB : <input type="text" name="dob" /><br />
Gender : <select name="gender">
<option value="M">Male</option>
<option value="F">Female</option>
</select><br />
Country : <select name="country">
<option value="US">United States of America</option>
<option value="AU">Australia</option>
<option value="CA">Canada</option>
<option value="XX">XXXXX</option>
</select><br />
<input type="submit" value="Submit Info" />
</form>

and in your php script to which you POST the form data, you can access the variables using $_POST[variablename].

echo $_POST['name'];
echo $_POST['dob'];
echo $_POST['gender'];
echo $_POST['country'];

so if you need to enter the data into mysql u can put these variables directly into the query.

mysql_connect(mysql_server, username, password);
mysql_select_db(db_name);
mysql_query("INSERT INTO table_name (name, dob, gender, country) VALUES ('$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[country]')");

this is just the basic steps to go about doing it. when ur applying this into ur script, you might want to organize it a bit more with validating form data and using local variables etc. hope you understood the common way of handling combo boxes in php.. let us know if u need more help.