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

#13 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:23 AM

then you create a select box with the values, you can take them from the db if you got a nice list there, probably looking like this:
<select name="field1">
<option value="[your code]">[user shown text for the code]</option>
</select>
for each option.
then, your form posts this and the selected one's value will turn up in the $_POST (or $_GET) variable as $_POST['field1'] having the value of the chosen code.
  • 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.


#14 qnstner

qnstner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 05 February 2010 - 07:31 AM

Yes, i was thinking that tought myself.

This is my code for writing to the select option where $row is the SQL query.
echo "<OPTION VALUE=\"".$row["point_num"]."\">".$row["point_num"]. " " .$row["point_text"]."</OPTION>";

But i really don't know how to accomplish what you just described.
  • 0

#15 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:35 AM

in the page which receives the POST/GET info, you need to read out the field name and then update your database according to to input.
  • 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.


#16 qnstner

qnstner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 05 February 2010 - 07:55 AM

Okey!

so it would be something like this? :

$value = $_POST
$input = "UPDATE points SET alarm=0 WHERE point_num="$value""
echo $input
  • 0

#17 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:58 AM

no, you need to connect to the database server with
mysql_connect() (or even better with mysqli_connect() but then need to use mysqli for all these)
then select database with mysql_select_db()
and also send the query with mysql_query()
  • 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.


#18 qnstner

qnstner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 05 February 2010 - 08:01 AM

hehe, yes i know! But i didn't write that here.

But anyways:

Here is what i've done.
HTML code for form:

<form name="sendaktiv" action="sendaktiv.php" method="POST">

sendaktiv.php:

mysqlblabla

$value = $_POST
$input = "UPDATE points SET alarm=0 WHERE point_num="$value""
echo $input

but i can't get it to work
  • 0

#19 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 - 08:11 AM

$value = $_POST['fieldname']; should do it. where fieldname is what you have in the name attribute of your select tag.
  • 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.


#20 qnstner

qnstner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 05 February 2010 - 08:29 AM

Okey!

hm, but i still cant get it to work.

My HTML:

<form name="sendaktiv" action="sendaktiv.php" method="POST">
<select size="10" name="aktiv_alarm" id="aktiv_alarm">
<?php header ('Refresh: 2');
include 'aktivalarmQ.php'
?>
</select>
<input type="button" name="acknowledge" value="Acknowledge" class="ack">
</form>


My sendaktiv.php:

<?php
$connect = mysql_connect('localhost', 'user', 'pw');
$db = mysql_select_db('alarm', $connect;

$value = $_POST['aktiv_alarm'];
$alarmack = mysql_query("UPDATE points SET Alarm='0' WHERE point_num = "$value"");
echo $alarmack;
?>

I think maybe it has something to do with my HTML file.

Edited by Orjan, 05 February 2010 - 09:25 AM.
Use code tags please!!!

  • 0

#21 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 - 09:27 AM

your button won't do a thing unless you have a javascript connected to it. if you change type to submit, it will work.
  • 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.


#22 chad

chad

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 59 posts

Posted 08 February 2010 - 11:48 PM

<input type="button" name="acknowledge" value="Acknowledge" class="ack">

change this one into

<input type="submit" name="acknowledge" value="Acknowledge" class="ack">
  • 0

#23 Orjan

Orjan

    CC Mentor

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

Posted 09 February 2010 - 06:52 AM

wasn't that what I said?
  • 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.


#24 chad

chad

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 59 posts

Posted 09 February 2010 - 06:04 PM

uhhh yes that is according to what Orjan said :P
  • 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