Page 1 of 1
[SOLVED] Please help with delete
Posted: Sun Aug 15, 2004 11:32 am
by melindaSA
I am going crazy can someone please take a look at the following, It will not work, and the result is a blank page -- does not show the error!!
Code: Select all
<?php
include('../newsletter_inc_fns.php');
$id = $HTTP_GET_VARS['id'];
$query = "delete from site_page_items where id='$id'";
$result = mysql_query($query) or die(mysql_error());
if(!$result == TRUE)
{
header("location:sitemanager.php?msg=suc");
}
else
{
header("location:sitemanager.php?msg=fail");
}
?>
Posted: Sun Aug 15, 2004 12:22 pm
by markl999
The include might be failing.
Try putting this at the top:
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//rest of your code below
?>
..see if that shows what the problem is.
Posted: Sun Aug 15, 2004 3:47 pm
by melindaSA
Thank you, It was my include!
Posted: Sun Aug 15, 2004 5:18 pm
by melindaSA
It is still not working, I changed to the following, and get my success message, but it has not deleted from the database:
Code: Select all
<?php
include('../database/dbconnect.php');
if ($_POST['id'])
{
$query = "delete from site_page_items where id='$id'";
$result = mysql_query($query) or die(mysql_error());
header("location:sitemanager.php?msg=suc");
}
else
{
header("location:sitemanager.php?msg=fail");
}
?>
Please help! Thank you!
Posted: Sun Aug 15, 2004 5:21 pm
by markl999
If you have register_globals Off (which you should) then you'll need to use:
$query = "delete from site_page_items where id='".$_POST['id']."'";
as $id won't be set. Leaving the error_reporting(E_ALL); at the top would catch this.
Posted: Sun Aug 15, 2004 5:29 pm
by melindaSA
That still does not work, I still get the success message, but not deleted from database.
I tried the following, and now it deleted all the records from the table??
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include('../database/dbconnect.php');
if ($_POST['id'])
{
$query = "delete from site_page_items where id=".$_POST['id'];
$result = mysql_query($query) or die(mysql_error());
header("location:sitemanager.php?msg=suc");
}
else
{
header("location:sitemanager.php?msg=fail");
}
?>
??now I am not sure??
Posted: Sun Aug 15, 2004 5:34 pm
by markl999
Okie, after this line:
$query = "delete from site_page_items where id=".$_POST['id'];
put:
echo $query;
and see what that outputs, make sure it 'looks ok'.
I'd also comment out the actual mysql_query() line whilst testing to avoid any mass db deletions

Posted: Sun Aug 15, 2004 5:45 pm
by melindaSA
I get:
delete from site_page_items where id='id'
So it seems like I am not pulling the id from the form. Here is the form code:
Code: Select all
<?php
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<form name="frmsite" action="" method=post>
<table width="95%" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td colspan="3"><font face="verdana, arial, sans-serif" size=2>Select Item :</font></td>
<td width="61%">
<?if($_SESSION["usrname"]=="****"){?>
<select name="mmenu" >
<option value='-1'><font face="verdana, arial, sans-serif" size=2>Select Item</font></option>
<?
$sql = "select * from site_page_items";
$res = mysql_query($sql) or die("Error :".mysql_error());
if (mysql_num_rows($res) > 0)
{
while($result = mysql_fetch_array($res))
{
echo "<option value='".$result['id']."'>".$result['item_title']."</option>";
}
}
?>
echo "<option value='1'>New Newsletter</option>";
</select>
<?}?>
</td>
</tr>
<tr>
<td colspan="3"> </td>
<td width="61%"> </td>
</tr>
<tr>
<td width="4%"> </td>
<td width="26%"> </td>
<td width="9%">
<input type="button" name="Button" value="Edit/Add" onclick="javascript:editsite()";>
</td>
<td width="61%">
<input type="button" name="Submit2" value="Delete" onclick="javascript:deletesite()";>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
?>
and here is the javascript code:
Code: Select all
function deletesite()
{
if (document.frmsite.mmenu.value == '-1')
{
alert("Select the Menu Item");
return false;
}
if (document.frmsite.mmenu.value == '1')
{
alert("Cannot delete this item");
return false;
}
if (confirm("Deleting this page cause this page unavailable when clicking any link related to it from anywhere in the site - \nAre you sure delete this Web Site Page ?"))
{
document.frmsite.action = "deletesitepage.php";
document.frmsite.submit();
}
}
Posted: Sun Aug 15, 2004 5:52 pm
by markl999
It looks like mmenu is the value you're trying to use, so maybe you need to be using $_POST['mmenu'] rather than $_POST['id'].
Posted: Sun Aug 15, 2004 5:58 pm
by melindaSA
OH!! I am so dumb!!

I missed that!!
Thank you

Posted: Sun Aug 15, 2004 6:00 pm
by markl999
It's alot easier to debug someone elses code rather than your own ... easily done
