could someone please help me with this problem, sorry for the Language in the code. Im trying to make it that way, that when someone selects a option and clicks the button that it will be inserted into my database, I already checked out if the name are all correct and such, and they are.
Note: Im not trying to select a value from my database, into my dropdown list, only to insert the value, like a application form for an account.
Note: If someone has asked the same question, it would be Awesome! if you could paste link in the comments, Thanks.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="room" value="options">
<option value="Einstaklings" name="102">Alment Einstaklings Herbergi</option>
<option value="Tveggja" name="102">Alment Tveggja manna Herbergi</option>
<option value="Business" name="201">Business Herbergi</option>
<option value="Fjolskyldu" name="301">Fjölskyldu Herbergi</option>
<option value="Svitu" name="401">Svítu</option>
</SELECT>
<input type="submit" value="Senda"/>
</form>
<?php
$db_tengi=@mysql_connect('localhost', 'root', '');
if (!$db_tengi) {
exit('<p>Cant Connect</p>');
};
if(!@mysql_select_db('hotel')){
exit('<p>Cant Connect</p>');
};
$room = array(
'Einstaklings' => 101,
'Tveggja' =>102,
'Business' => 201,
'Fjolskyldu' =>301,
'Svítu' => 401
);
function generateSelect($name = '', $options = array()) {
$html = '<select name="'.$name.'">';
foreach ($options as $option => $value) {
$html .= '<option value='.$value.'>'.$option.'</option>';
}
$html .= '</select>';
return $html;
}
$html = generateSelect('room', $room);
if (
$sql = "INSERT INTO `registration` SET
room_ID_FK='$room'"
)
if(@mysql_query($sql)){
echo '<p> Insert Complete</p>';
}
else{
echo '<p> Error Insert failed.' . mysql_error() . '</p>';
};
?>
1) In your select don’t give names to each option
2) You need to recieve your posted data, it will be in superglobal array $_POST
3) You need to write this data to Data Base, after you made connection to it