<select name="propinsi"> <option value="Pilih" selected="selected">Pilih salah satu....</option> <option>Nanggroe Aceh Darussalam</option> <option>Sumatera Utara</option> <option>Sumatera Barat</option> <option>Bengkulu</option> <option>Riau</option> <option>Kepulauan Riau</option> <option>Jambi</option> <option>Sumatera Selatan</option> <option>Lampung</option> <option>Kepulauan Bangka Belitung</option> <option>DKI Jakarta</option> <option>Jawa Barat</option> <option>Banten</option> <option>Jawa Tengah</option> <option>DI Yogyakarta</option> <option>Jawa Timur</option> <option>Kalimantan Barat</option> <option>Kalimantan Tengah</option> <option>Kalimantan Selatan</option> <option>Kalimantan Timur</option> <option>Bali</option> <option>Nusa Tenggara Barat</option> <option>Nusa Tenggara Timur</option> <option>Sulawesi Barat</option> <option>Sulawesi Utara</option> <option>Sulawesi Tengah</option> <option>Sulawesi Selatan</option> <option>Sulawesi Tenggara</option> <option>Gorontalo</option> <option>Maluku</option> <option>Maluku Utara</option> <option>Papua Barat</option> <option>Papua</option> </select>
put a value from mysql into select
Started by yonghan, Mar 02 2009 09:04 PM
26 replies to this topic
#1
Posted 02 March 2009 - 09:04 PM
Hi all, i'm using this code in a registration form to get the values into mysql..Suppose the user want to edit their profile,how do i display the values from the mysql into select..Thanks a lot...This code is for selecting province..
|
|
|
#2
Posted 02 March 2009 - 11:46 PM
So you wish to select what the user has chose and then input into a MySQL table?
If so, have you set up a MySQL databse yet? If so, you first need to make a MySQL connection. Also you have to connect to the databse.
Once the connection is made you must first retrieve the users input. You must put the above input selection tags into a form with the action of a PHP file. The method must also be post.
Then in the new PHP file, you must add the mysql_connect function and also the following code which will retrieve the users input.
Now you have that, you must insert the user information into a table.
Any further help just ask.
If so, have you set up a MySQL databse yet? If so, you first need to make a MySQL connection. Also you have to connect to the databse.
$connect = mysql_connect('hostname', 'username', 'password');
$db = mysql_select_db('database_name', $connect);
Once the connection is made you must first retrieve the users input. You must put the above input selection tags into a form with the action of a PHP file. The method must also be post.
<form action="new.php" method="POST"> //Input tags go in here </form>
Then in the new PHP file, you must add the mysql_connect function and also the following code which will retrieve the users input.
$user_input = $_POST['propinsi'];
Now you have that, you must insert the user information into a table.
$input = "INSERT INTO `table_name` ('column1', 'column2') VALUES ($user_input, 'name');
Any further help just ask.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#3
Posted 03 March 2009 - 02:20 AM
For such a list, it's much easier to create an sql table and put your values there, and assign each name with an id number, as number matching is better than string matching. Also, it is safer for eventual spelling errors and stuff.
$userprop = 15; // in your way, take the users value from the database
// or if it is at registration, set at wished default value
$res = mysql_query("select id, name from propinsi");
echo '<select name="propinsi">';
while ($row = mysql_fetch_array($res)) {
if ($row['id'] == $userprop) {
echo '<option value="'.$$row['id'].'" selected="selected">'.$row['name'].'</option>';
} else {
echo '<option value="'.$$row['id'].'">'.$row['name'].'</option>';
}
}
echo '</select>';
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#4
Posted 03 March 2009 - 02:27 AM
Thanks orjan..I will try the way you taught me..
#5
Posted 03 March 2009 - 03:35 AM
Hold on, with what Orjan has said. I am confused on what you want to do?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#6
Posted 03 March 2009 - 04:05 AM
I'm intending to get the values that user had choosed before and put it into select option..
#7
Posted 03 March 2009 - 01:12 PM
Yes sorry, follow Orjan's code. I read your question wrong.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#8
Posted 05 February 2010 - 04:45 AM
Brandon W said:
So you wish to select what the user has chose and then input into a MySQL table?
If so, have you set up a MySQL databse yet? If so, you first need to make a MySQL connection. Also you have to connect to the databse.
Once the connection is made you must first retrieve the users input. You must put the above input selection tags into a form with the action of a PHP file. The method must also be post.
Then in the new PHP file, you must add the mysql_connect function and also the following code which will retrieve the users input.
Now you have that, you must insert the user information into a table.
Any further help just ask.
If so, have you set up a MySQL databse yet? If so, you first need to make a MySQL connection. Also you have to connect to the databse.
$connect = mysql_connect('hostname', 'username', 'password');
$db = mysql_select_db('database_name', $connect);
Once the connection is made you must first retrieve the users input. You must put the above input selection tags into a form with the action of a PHP file. The method must also be post.
<form action="new.php" method="POST"> //Input tags go in here </form>
Then in the new PHP file, you must add the mysql_connect function and also the following code which will retrieve the users input.
$user_input = $_POST['propinsi'];
Now you have that, you must insert the user information into a table.
$input = "INSERT INTO `table_name` ('column1', 'column2') VALUES ($user_input, 'name');
Any further help just ask.
Hi Brandon!
Im trying to do something like you described. What i have is a select form where the options comes from a MySQL database. My SQL command is:
SELECT test_num, test_text, test_type FROM test WHERE al='1'
This is working fine.
What i want to do is when i select an option and press a button i would like to send 0 back to al from the selected option to MySQL. The Values of each option is test_num and they are unique.
Do you know if it's possible to accomplish this?
Best regards.
#9
Posted 05 February 2010 - 06:22 AM
qnstner said:
What i want to do is when i select an option and press a button i would like to send 0 back to al from the selected option to MySQL. The Values of each option is test_num and they are unique.
What do you mean by sending 0 back to all? I don't understand what you want to achieve?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#10
Posted 05 February 2010 - 07:08 AM
i want to send the value "0" to the record "al" in MySQL when i have selected an option and pushed a submit button.
I reality it means that i want to acknowledge one alarm.
I reality it means that i want to acknowledge one alarm.
#11
Posted 05 February 2010 - 07:10 AM
is this depending on what the user chooses in the select, or what?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#12
Posted 05 February 2010 - 07:11 AM
yes, because every option has it's own "al" record.


Sign In
Create Account


Back to top









