[How]Delete button
Moderator: General Moderators
Re: [How]Delete button
so what the "excution" trigger to delete the record?
Re: [How]Delete button
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...
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
you said that i dont need button...
so how to delete my record,
i mean how to tell php to delete already checked record?
so how to delete my record,
i mean how to tell php to delete already checked record?
Re: [How]Delete button
No, I said you don't need the foreach loop.
Look, to delete one record:
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());- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: [How]Delete button
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.
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.
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" />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
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.
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
I try to doing search like jack told me,
and i found, but i've changes few codes...
Now it's work
But when i try to revert > PHP inside HTML
it doesnt work why?
like this...
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>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
Have you turned on error reporting? Looks like you're embedding PHP tags...
Re: [How]Delete button
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?

now im going to make this "check all" work...
could u help me...
should it be better if use pagination?

Re: [How]Delete button
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.
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.