mysql - Updating a field from an sql table from php -


i have table more columns. on 1 column have 3 buttons each row different queries associated. when click 1 of buttons, field in table database should update.the problem when click on button on row in table, updates field first row.for example, have table 10 rows.if click 1 of buttons on 10th row update first row, not 10th 1 want. there possibility solve this? code..i'm sorry long:

    <?php $query = "select * masculin order id_concurent";             $result = mysqli_query($link ,$query);     $row = mysqli_fetch_assoc($result);       if(isset($_post['locul1']))     {         $sql = "update masculin set premiu=1 cnp='".$row['cnp']."'";               mysqli_query($link,$sql);         header("location:administrare.php");     }     else if(isset($_post['locul2']))     {         $sql = "update masculin set premiu=2 cnp='".$row['cnp']."'";           mysqli_query($link,$sql);         header("location:administrare.php");     }     else  if(isset($_post['locul3']))     {         $sql = "update masculin set premiu=3 cnp='".$row['cnp']."'";               mysqli_query($link,$sql);         header("location:administrare.php");     }   ?>    <u><i><h1 align="center">administrare concurenti</h1></i></u> <u><i><h2>masculin</h2></i></u>  <?php             $query = "select * masculin order id_concurent";             $result = mysqli_query($link ,$query);             if (mysqli_num_rows($result) == 0) {                     echo 'inca nu s-a inscris niciun concurent.';             } else {         ?> <table width="100%">     <tr>         <th>nr.<br />concurs</th>         <th>nume</th>         <th>prenume</th>         <th>cnp</th>         <th>categoria</th>         <th>varsta</th>         <th>premiu</th>         <th>modifica<br />rezultat</th>         <th>descalifica</th>     </tr>          <?php while($row = mysqli_fetch_assoc($result)){ ?>         <tr>             <?php              $query1="select id_concurent  concurenti cnp='".$row['cnp']."'";                 $result1=mysqli_query($link,$query1);                 $nr_conc=mysqli_fetch_assoc($result1);             ?>             <td> <?php echo $nr_conc['id_concurent'] ?> </td>             <td> <?php echo $row['nume'] ?> </td>             <td> <?php echo $row['prenume'] ?> </td>             <td> <?php echo $row['cnp'] ?> </td>             <td> <?php echo $row['categorie'] ?> </td>             <td> <?php echo $row['varsta'] ?> </td>             <td> <?php echo $row['premiu'] ?> </td>                      <td>             <form action="administrare.php" method="post">                           <input type="submit" name="locul1" value="premiul 1">                  <input type="submit" name="locul2" value="premiul 2">                  <input type="submit" name="locul3" value="premiul 3">                    </form>                      </td>         </tr>             <?php } ?>     </table>     <?php  } ?> 

for updated da tbale row when submit values related html table row should add , hidden input value let reach correct row eg:

  <form action="administrare.php" method="post">                 <input type="submit" name="locul1" value="premiul 1">        <input type="submit" name="locul2" value="premiul 2">        <input type="submit" name="locul3" value="premiul 3">              <input type="hidden" name="cnp" value="<?php echo $row['cnp'] ?>">   </form> 

and in sql updated query add post value related row

  $sql = "update masculin set premiu=1 cnp='".$_post['cnp']. "'";    

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -