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

}

?>

Archived

This topic is now archived and is closed to further replies.

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