I created a dropdown list with 6 options.
After select an option and clicking the submit button, the selected value should be inserted into the mysql database. This is code:
<form name="name" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select id="broj" name="name">
<option value="0">--Select--</option>
<option value="2">Option 1</option>
<option value="3">Option 2</option>
<option value="4">Option 3</option>
<option value="5">Option 4</option>
<option value="6">Option 5</option>
<option value="7">Option 6</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_GET){
$result= $_GET['name'];
}
?>
//
After this follows the code that inserts the $result into the mysql database
I have two problems with this code:
As soon as the page is opened (before clicking the button) , the value 0 is inserted into the database (value of "Select" option)
After refreshing page, the selected value is re-insert into the database
How to make the selected option inserted into the database only when the submit button is clicked