html - Executing PHP if a link is clicked -


i've been searching around internet, , of course stackoverflow answers on how execute php command when link clicked. here basic code have that's trying either 'update' or 'delete' data within form.

if(isset($_get['delete'])){                  $sql = "delete addresses id ='$_post[id]'";                 mysql_query($sql,$conn);                 header("location: form.php");             };      if (isset($_get['update'])){                 $sql = "update addresses set firstname='$_post[firstname]', lastname='$_post[lastname]', age='$_post[age]' id='$_post[id]'";                 mysql_query($sql,$conn);                 header("location: form.php");             };     ?> 

<?php while ($row = mysql_fetch_array($retreve, mysql_assoc)) {      echo "<form action=form.php method=post>";     echo "<tr>";     echo "<td><input type=text name=firstname value={$row['firstname']}> </td>";     echo "<td><input type=text name=lastname value={$row['lastname']}> </td>";     echo "<td><input type=text name=age value={$row['age']}> </td>";     echo "<td><input type=hidden name=id value={$row['id']}> </td>";     //links insead of buttons     echo "<td><a href = # id='update'> update</a></td>";     echo "<td><a href = # id='delete'> delete</a> </td>";  }  

i have above functions i'm trying call whenever click links "update" , "delete". suppose in order php execute.

note: database connection not shown connected.

echo "<td><a href = 'form.php?type=delete&id=99' id='delete'> delete</a> </td>"; 

{$row['id']} 99 in particular case then:

if($_get['type']=='delete'){                      $sql = "delete addresses id ='$_get[id]'";                     mysql_query($sql,$conn);                     header("location: form.php"); }elseif ($_get['type']=='update'){  //  } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -