Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

put a value from mysql into select

registration mysql

  • Please log in to reply
26 replies to this topic

#1 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

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..


<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>

  • 0

#2 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

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.

$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.
  • 0
I've returned...

#3 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

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>';

  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#4 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 03 March 2009 - 02:27 AM

Thanks orjan..I will try the way you taught me..
  • 0

#5 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 03 March 2009 - 03:35 AM

Hold on, with what Orjan has said. I am confused on what you want to do?
  • 0
I've returned...

#6 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

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..
  • 0

#7 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 03 March 2009 - 01:12 PM

Yes sorry, follow Orjan's code. I read your question wrong.
  • 0
I've returned...

#8 qnstner

qnstner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 05 February 2010 - 04:45 AM

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.


$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.
  • 0

#9 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 05 February 2010 - 06:22 AM

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?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#10 qnstner

qnstner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

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.
  • 0

#11 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 05 February 2010 - 07:10 AM

is this depending on what the user chooses in the select, or what?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#12 qnstner

qnstner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 05 February 2010 - 07:11 AM

yes, because every option has it's own "al" record.
  • 0





Also tagged with one or more of these keywords: registration, mysql

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download