0

I have a problem with my update and I can undertsand where is my mistake So ,my table in database:place with (id,place_number,rezerv) And I have a form:

<form id="formid" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> 
      <label>Place :</label> 
      <select name="place_number" class="place_number" id="place_number">
          <option selected="selected">-Select-</option>
      </select>
      <input name="update" type="submit" id="update" value="Update" />
 </form>

And the php code:

   <?php
      $link = mysql_connect("localhost", "user", "user")
    or die("Can't connect to mysql server");

$db = mysql_select_db("dt_base",$link)
    or die("Can't select database");

    if(isset($_POST['update']))
    {
     if($_POST['place_number'])
     {
      $place_number = $_POST['place_number'];
  mysql_query("UPDATE place SET rezerv = 1 WHERE place_number = '$place_number'",$link);
      }
    }
  ?>

1 Answers1

3

Try this in your form field:

<select name="place_number" class="place_number" id="place_number">
      <option selected="selected">-Select-</option>
      <option value="1" selected="selected">Place 1</option>
      <option value="2" selected="selected">Place 2</option>
  </select>

And then try again.

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • I need to populate the select box with date from database? – user3036261 Nov 26 '13 at 12:10
  • We don't know where you get your data from. But if you want the user to select a place number you will have to put some data in the dropdown, right? – CompuChip Nov 26 '13 at 12:18
  • Like this: $sql=mysql_query("select id,place_number from place"); while($row=mysql_fetch_array($sql)) { $id=$row['id']; $place_number=$row['place_number']; echo ''; } – user3036261 Nov 26 '13 at 12:20
  • Yes. Like that. I would like to note that the use of the mysql_query is very old and soon to be abolished. I'd suggest you step over to mysqli(basically the same) or PDO for your queries. – Tschallacka Nov 26 '13 at 15:49