Code: Select all
<?php
foreach ($_POST['checkbox'] as $value) {
$query = "DELETE * FROM recommendations WHERE entryid = '". mysql_real_escape_string($value) ."' ";
$deleteSql = mysql_query($query);
}
?>Moderator: General Moderators
Code: Select all
<?php
foreach ($_POST['checkbox'] as $value) {
$query = "DELETE * FROM recommendations WHERE entryid = '". mysql_real_escape_string($value) ."' ";
$deleteSql = mysql_query($query);
}
?>You probably could but then you would have to check which action is to take place. With delete (using the form) you check if the post button has been set. Your update option uses an anchor tag so you can simply check if the query string value is set.timoteo wrote:But can I send the form to 2 separate pages - one to delete and one to update? I understand that I am not getting the variable. How can I select one entry from my displayed rows to delete or update?
Code: Select all
<?php
// this is your single page (if you want to use a single page)
if (isset($_POST['yourPostButton'])) {
// delete records
}
if (isset($_GET['yourUpdateValue'])) {
// update record
}
?>Code: Select all
<form action="recommendationsupdate.php" method="get" enctype="application/x-www-form-urlencoded" name="myrecommendations" target="_self" id="myrecommendations">Code: Select all
<input name="update" type="submit" id="update" value="update">
<input name="delete" type="submit" id="delete" value="delete" onClick = "return confirm('Are you sure you want to delete this recommendation?')">
</div></td>
</tr>
</table>
<?php
if
($_POST['delete']=='delete'){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE*FROM $recommendations WHERE numid='$del_id'";
$result = mysql_query($sql);
}
}
if($result)
{
echo "<meta http-equiv=\"refresh\" content=\";myrecommendations.php\">";
mysql_close();
}
else if ($_GET['update']=='update')
{
?>
<td><a href="recommendationsupdate.php" action = update=$_GET['checkbox']>update</a><td/>
<?php
?>
<?php
}
?>
Code: Select all
<?php
if ($_POST['delete']=='delete'){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE*FROM $recommendations WHERE numid='$del_id'";
$result = mysql_query($sql);
}
?>Code: Select all
<?php
foreach ($_POST['checkbox'] as $value) {
$id = $value;
$sql = "DELETE * FROM table WHERE id = '". $id ."' ";
$result = mysql_query($sql);
}
?>Code: Select all
<?php
if
($delete) {
foreach ($_POST['checkbox'] as $value) {
$id = $value;
$sql = "DELETE * FROM table WHERE idnum = '". $id ."' ";
$result = mysql_query($sql);
}
?>
<form action="myrecommendations.php" method="post" enctype="application/x-www-form-urlencoded" name="myrecommendations" target="_self" id="myrecommendations">
<?php
}
else if ($update)
{
?>
<form action="recommendationsupdate.php" method="get" enctype="application/x-www-form-urlencoded" name="recommendationsupdate" target="_parent" id="recommendationsupdate">
<?php
}
?>
<p>
</p>
</div>
</form>I don't think you can have two action attributes for one form.timoteo wrote:I want the update to be on a separate page from the delete - one form 2 actions
You will have to create another form, or have the update option accessed via a hyperlink. If you use the hyperlink, you can pass the value ($id) along in a query string.timoteo wrote:If the update button is pressed I want just a simple redirect to another page (with checkbox as value to display relevant results). If the delete button is pressed I want delete action on relevant results.
That sounds like a great idea, however how can I attach and pass the value along. This is what I had tried but there is no value passed on.You will have to create another form, or have the update option accessed via a hyperlink. If you use the hyperlink, you can pass the value ($id) along in a query string.
Code: Select all
<a href="recommendationsupdate.php" title="recommendationsupdate" accesskey="u" value = <?php echo $_GET['checkbox'] ?>>updateCode: Select all
<?php
foreach ($_POST['checkbox'] as $value) {
$id = $value;
$sql = "DELETE * FROM table WHERE id = '". $id ."' ";
$result = mysql_query($sql);
}
?>The checkbox is this:Warning: Invalid argument supplied for foreach() in /home/... on line 283
Code: Select all
<input name="checkbox" type="checkbox" value=<?php echo $row_rsrecommendations['idnum']?>>Code: Select all
<a href="recommendationsupdate.php" title="recommendationsupdate" accesskey="u" value = <?php echo $_GET['checkbox'] ?>>updateCode: Select all
<a href="recommendationsupdate.php?id='. dbValueHere .'" title="recommendationsupdate" accesskey="u">Update</a> Code: Select all
<input name="checkbox" type="checkbox" value=<?php echo $row_rsrecommendations['idnum']?>>Code: Select all
<input name="checkbox[]" type="checkbox" value="<?php echo $row_rsrecommendations['idnum']; ?>" />Code: Select all
<td><input name="checkbox[]" type="checkbox" value="<?php echo $row_rsrecommendations['idnum']; ?>" />Yes it will do that because the html was changed to tell php that $_POST['checkbox'] should be an array. Do you still get the foreach error?timoteo wrote:This yields no output - and when I echo out $_POST['checkbox'] it just echos "array" (no id).