delete a row on mysql with php issue -


im trying delete row on php (i did it) but, delete last row, know why... because everytime refresh or enter in page, everytime got id = "lastrow", issue is, dont know why everytime got last row id...`$query = "select * ph"; $rs = mysql_query($query);

    while ($ph = mysql_fetch_array($rs)) {       echo utf8_encode("         <tr class='etapastext'>           <td >             ".$ph['name']."           </td>           <td>             <input type='submit' name='".$ph['id']."' value='eliminar' >             <input type='hidden' name='name'  value='".$ph['id']."'>           </td>           "); }` 

then can access id of item wish delete, use code

$query = "delete  ph ph.id = '".$_post['name']."'"; mysql_query($query); 

i'm using $_post['name'] because form, dont know if im doing best way or im doing bad

i echoed $query got delete ph ph.id = '24' when "24" last row on table

as definition, there should unique name every input type in single form, doing giving multiple input types

name="name" 

so technically when form submitted last input type name='name' sent form. that's doing wrong. not pro according me have 3 options delete row form database table.

  1. use method send value url (best way)

    www.xyz.com/delete.php?id=5

  2. (will mess code) use individual form , submit button each , every input type , important, form should start in td

  3. you create form on run time javascript, , based on selected row values filled , form submitted, (recommended if want use post because make code clean)

hope help


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -