0

i have a form based on database mysql ,just like this

<form name="" id="form1" method="GET" action="submit.php"></form> 
<?php 
include 'connection.php';
$myquery="SELECT * FROM `tbl` " ;
$params=mysql_query($myquery) or die (mysql_error()); 
while ($param=mysql_fetch_assoc($params))
{?> 

   <input name="<?php echo $param['id'] ?>" value="<?php echo $param['child_id'] ?>" />
   <input type="checkbox" name="checkbox<?php echo $param['id'] ?>" value="Yes" form="form1" />  
   <input class="form-control text-center" form="form1" name="desc<?php echo $param['id'] ?>" value="<?php echo $param['desc'] ?>"/>
   <input class="form-control text-center" form="form1" name="value <?php echo $param['id'] ?>" value="<?php echo $param['value'] ?>"/>
   <select class="form-control" form="form1" id="" name="select<?php echo $param['id'] ?>">          
      <option value=""></option>
      <option value="OK">OK</option>
      <option value="NOK">NOK</option>
   </select>
<?php } ?>
 <button type="submit" class="btn  btn-success btn-s-md btn-rounded" form="form1"><i class="icon-save"></i>Save</button>

how can i submit (do update ) to mysql database with this form , i am a newbie in php . thanks

sirahanzo
  • 5
  • 5

2 Answers2

1

So yes you have to add the balise form at this end. Then I advice you to add a hidden value with your id.

<input type="hidden" name"id" value="<?php echo  $param['id'] ; ?>">

After ad in your page submit.php,

<?php
include 'connection.php';
if (isset($_POST["id"])){ 
$id=$_POST["id"];#so you can recover your id
$myquery="UPDATE ... " ;
mysql_query($myquery) or die (mysql_error());
echo "update success";# you can add whatever you want here 
}?>
caroline
  • 98
  • 5
1

You have to wrap all your form elements into the <form> tag. So place your closing tag (</form>) at the end of your form.

<form name="" id="form1" method="GET" action="submit.php">
    <input name="..." />
    <select>          
        <option value="...">...</option>
        ...
    </select>
    <button>...</button>
</form>

By the way: PHP's mysql-functions are deprecated. Use mysqli instead!

Community
  • 1
  • 1
Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116