Jump to content

Sending information from Dropdown list to MySQL


hannap

Recommended Posts

I have a problem with saving data gained with Dropdown list. The script below saves the length of the vector $labels (which is 3) instead of the value chosen from a dropdown list. How can I save the value chosen from a Dropdown list to the MySQL table? Thank you!!

 

<?php

 

mysql_connect("","root");

mysql_select_db("chat");

$res1=mysql_query("select labelm1 from collaboration_cross1 where labelm1 != ''");

$dsatz1 = mysql_fetch_assoc($res1);

$labm1=$dsatz1["labelm1"];

$res2=mysql_query("select labelm2 from collaboration_cross1 where labelm2 != ''");

$dsatz2 = mysql_fetch_assoc($res2);

$labm2=$dsatz2["labelm2"];

 

$labels = array(

'' => 1,

$labm1 => 2,

$labm2 => 3

);

 

 

function generateSelect($name, $options) {

$html = '<form name="f" action="dropdown_CROSS1.php" method="post"><div align="center"><label for="frmcounty">Label:</label><select name="'.$name.'" id="LabelChos">';

foreach ($options as $option => $value) {

$html .= '<option value='.$value.'>'.$option.'</option>';

}

$html .= '</select></div></form>';

echo "$html";

return $value;

}

 

$value = generateSelect('labelchosen', $labels);

if(isset($value))

{

mysql_connect("","root");

mysql_select_db("chat");

mysql_query("insert into collaboration_cross1 (labelchosen1)

values ('" . $value . "')");

 

/* Chat-Anzeige aktualisieren */

echo "<script type='text/javascript'>

reload();</script>";

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.