Page 1 of 1

Delete a Row in a table

Posted: Mon Oct 04, 2010 11:33 am
by frmmythili
I have used the below code to delete a row in the table and it's not working..

Can anybody help me out


<?php
<input name="delete" type="button" id="delete" value="Delete" onclick="delete()">
<br />
<br />
</label></td>
</tr><?php
$count=mysql_num_rows($qryselect);
echo $count;
// Check if delete button active, start this

function delete(){
echo "working";

for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
echo $del_id;
$sql = "DELETE FROM tbl_project WHERE id='$del_id'";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete.php\">";
}
}

?>

Re: Delete a Row in a table

Posted: Mon Oct 04, 2010 12:09 pm
by Jonah Bron
You can't call a PHP function like that. That's Javascript. PHP is executed on the server before the user gets it: the client cannot see PHP. Instead of a button, make a link that goes to (for example) delete.php?id=[id of the row to delete]. You can access that ID in delete.php with $_GET['id'].