Page 3 of 3
Re: [How]Delete button
Posted: Fri Aug 21, 2009 10:20 am
by nitediver
so what the "excution" trigger to delete the record?
Re: [How]Delete button
Posted: Sat Aug 22, 2009 6:08 am
by jackpf
I don't understand.
If you're trying to delete multiple records, google "php multiple checkbox" or something similar.
Otherwise, you need to explain a bit better...
Re: [How]Delete button
Posted: Sat Aug 22, 2009 10:10 am
by nitediver
you said that i dont need button...
so how to delete my record,
i mean how to tell php to delete already checked record?
Re: [How]Delete button
Posted: Sat Aug 22, 2009 10:14 am
by jackpf
No, I said you don't need the foreach loop.
Look, to delete one record:
Code: Select all
$id = (int) mysql_real_escape_string($_POST['delete']);
mysql_query("DELETE FROM `yourtable` WHERE `ID`='$id';") or die(mysql_error());
Re: [How]Delete button
Posted: Sun Aug 23, 2009 1:31 am
by JAB Creations
I recommend two inputs, one with a min and the other with a max value of the item's value. So if they are messages 20-30 set min to 20 and max to 30.
Code: Select all
<input name="delete" type="checkbox" value="1" /><input name="delete" type="checkbox" value="2" /><input name="delete" type="checkbox" value="3" /><input name="delete" type="checkbox" value="4" />
The name=delete in the input is going to create an array accessible in PHP as $_POST['delete']. Change the input name (on EVERY delete checkbox) to something else (like bob) and delete becomes bob ($_POST['bob']).
Then you should be able to do a quick foreach loop and determine if the value is set. You know by the post min and max what the range is. That's just my quick and dirty quick conceptual suggestion. I'm sure there is a better way.
Re: [How]Delete button
Posted: Sun Aug 23, 2009 4:58 am
by jackpf
Hey Jab, I think you need square brackets on the end of the names
But I'm still not sure what this guys wants to do. Are you deleting one or multiple records? Your code seems half and half...and it doesn't work.
I think you need to check out some tutorials imo.
Re: [How]Delete button
Posted: Fri Aug 28, 2009 10:14 am
by nitediver
I try to doing search like jack told me,
and i found, but i've changes few codes...
Now it's work
Code: Select all
<?
require("conn.php");
$do = "select * from invoice";
$qwery = mysql_query($do);
?>
<html><body>
<style type="text/css">
#list {border: #000000 1px solid; border-top:none;}
#head {border: #000000 1px solid;}
</style>
<form action="dialit.php" method="POST">
<?php
print ("
<table width=\"80%\" id=\"head\">
<tr>
<td width=\"5%\"></td>
<td width=\"20%\">Name</td>
<td width=\"20%\">Number</td>
<td width=\"20%\">Date</td>
</tr>
</table>
");
while ($result = mysql_fetch_array($qwery))
{
print ("
<table width=\"80%\" id=\"list\">
<tr>
<td width=\"5%\"><input type=checkbox name=del[] id=del value=$result[id]></td>
<td width=\"20%\">$result[name]</td>
<td width=\"20%\">$result[number]</td>
<td width=\"20%\">$result[date]</td>
</tr>
</table>
");
}
?>
<input type="submit" name="delete" value="Delete" id="delete">
<?php
$id = $_POST[del];
$multi = count($id);
if($_POST['delete'])
{
for ($i=0; $i<$multi; $i++)
{
$dodel = "delete from invoice where id=$id[$i]";
$qwerydel = mysql_query($dodel);
}
if ($qwerydel)
{
print "Record Deleted<br>";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=dialit.php\">";
}
}
?>
</form>
</body></html>
But when i try to revert > PHP inside HTML
it doesnt work why?
like this...
Code: Select all
<table width=\"80%\" id=\"list\">
<tr>
<td width=5%><input type=checkbox name=del[] id=del value=$result[id]></td>
<td width=20%><? print "$result[name]";</td>
..............
Re: [How]Delete button
Posted: Fri Aug 28, 2009 10:28 am
by jackpf
Have you turned on error reporting? Looks like you're embedding PHP tags...
Re: [How]Delete button
Posted: Thu Sep 17, 2009 8:10 am
by nitediver
sorry jack ive been away so long,
now im going to make this "check all" work...
could u help me...
should it be better if use pagination?

Re: [How]Delete button
Posted: Thu Sep 17, 2009 9:39 am
by jackpf
Lol wb.
What's not working?
And hmm...that depends on how many items you're likely to have. If it's more than about 25 then yeah...I'd personally paginate it.