Jump to content

Recommended Posts

guys,

i need help. i am setting up a CMS for my site. and there's a page
wherein i wanted to delete a specific item...
i can't make it work.
if i click on the delete button, the item is still there.

here is my script for the first page:
=================
<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("Do you really want to delete this?");
if (agree)
return true ;
else
return false ;
}
-->
</script>
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form name="frmUsers" method="POST" action="feedbackdelete.php">
<table width="610" border="1" cellspacing="0" cellpadding="0">
<?
include '../db_connect.php';

$uSql = "SELECT news_title, news_content, news_sender, news_date, newsid FROM news ORDER by news_date DESC";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
echo 'no data found';
}
else{
$currentTitle = "";
while($uRow = mysql_fetch_row($uResult)){
if($currentTitle != $uRow[0]) {
$currentTitle = $uRow[0];
echo "<tr><td class='bodytext3'>";
echo "<br>";
echo "<b>$currentTitle</b>";
echo "<br><br>";
echo "</td></tr>";

}?>
<tr>
<td width="606"><table width="612" border="0" cellspacing="0" cellpadding="0">

<tr>
<td width="481"><span class="bodytext">Message:</span><span class="bodytext6">
<?= $uRow[1]?>

</span></td>
<td width="116">&nbsp;</td>
</tr>
<tr>
<td><span class="bodytext">Sender:</span> <i><span class="bodytext6">
<?= $uRow[2]?>
</span></i></td>
<td width="116">&nbsp;</td>
</tr>
<tr>
<td><span class="bodytext">Date posted:</span><span class="bodytext6">
<?= $uRow[3]?>
<input type="hidden" name="nid" value="<?= $uRow[4]?>">
</span></td>
<td width="116"><input name="delete" type="submit" value="Delete Feedback" onclick="return confirmSubmit()" /></td>
</tr>
<tr><td colspan="2" class="bodytext"> -----------------------------------------------------------------------------</td> </tr></table></td></tr>
<?
}
}
?>
</table></form>
</td>
</tr>
</table></td>
</tr>
</table>
===========================
and here is my script for the feedbackdelete.php

===========================
<?
session_start();

if (session_is_registered("username")){

if($_SESSION['user_level'] == 0){

include '../db_connect.php';

$bid = $_POST['nid'];

$dusql="DELETE from news WHERE newsid='$nid'";
mysql_query($dusql) or die("error:".mysql_error());

echo '<script language=javascript>top.location = "feedback.php";</script>';
}
else{
echo '<script language=javascript> alert("You are not authorized to access this page!");top.location = "main.php";</script>';
}
}

else{
echo '<script language=javascript>top.location = "index.php";</script>';
}

?>
======================

hope you can help me with this....
thanks in advance!!!
Link to comment
https://forums.phpfreaks.com/topic/5754-delete-query-in-sql/
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
session_start();

if (session_is_registered("username")){

if($_SESSION['user_level'] == 0){

include '../db_connect.php';

$bid = $_POST['nid'];

$dusql="DELETE from news WHERE newsid='$_POST[nid]'";
mysql_query($dusql) or die("error:".mysql_error());

echo '<script language=javascript>top.location = "feedback.php";</script>';
}
else{
echo '<script language=javascript> alert("You are not authorized to access this page!");top.location = "main.php";</script>';
}
}

else{
echo '<script language=javascript>top.location = "index.php";</script>';
}

?>[/quote]

You didnt use $_POST on the nid by the looks of it mate
Link to comment
https://forums.phpfreaks.com/topic/5754-delete-query-in-sql/#findComment-20499
Share on other sites

bro,

its still not working.
for the $nid its just a typo
normally from my script its
========
<?
session_start();

if (session_is_registered("username")){

if($_SESSION['user_level'] == 0){

include '../db_connect.php';

$nid = $_POST['nid'];

$dusql="DELETE from news WHERE newsid='$nid'";
mysql_query($dusql) or die("error:".mysql_error());

echo '<script language=javascript>top.location = "feedback.php";</script>';
}
else{
echo '<script language=javascript> alert("You are not authorized to access this page!");top.location = "main.php";</script>';
}
}

else{
echo '<script language=javascript>top.location = "index.php";</script>';
}

?>
=====================

hope you can help me fix the problem.
because on my add section, i can successfully add and update items.
its just on the delete section wherein i am getting problems.

thanks!
Link to comment
https://forums.phpfreaks.com/topic/5754-delete-query-in-sql/#findComment-20591
Share on other sites

bro,

please check my script on the first page?
do you think the problem is in the first page?
==============

<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("Do you really want to delete this?");
if (agree)
return true ;
else
return false ;
}
-->
</script>

<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="455"><table width="624" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form name="frmnews" method="POST" action="feedbackdelete.php">
<table width="610" border="1" cellspacing="0" cellpadding="0">
<?
include '../db_connect.php';

$uSql = "SELECT news_title, news_content, news_sender, news_date, newsid FROM news ORDER by news_date DESC";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
echo 'no data found';
}
else{
$currentTitle = "";
while($uRow = mysql_fetch_row($uResult)){
if($currentTitle != $uRow[0]) {
$currentTitle = $uRow[0];
echo "<tr><td class='bodytext3'>";
echo "<br>";
echo "<b>$currentTitle</b>";
echo "<br><br>";
echo "</td></tr>";

}?>
<tr>
<td width="606"><table width="612" border="0" cellspacing="0" cellpadding="0">

<tr>
<td width="481"><span class="bodytext">Message:</span><span class="bodytext6">
<?= $uRow[1]?>

</span></td>
<td width="116">&nbsp;</td>
</tr>
<tr>
<td><span class="bodytext">Sender:</span> <i><span class="bodytext6">
<?= $uRow[2]?>
</span></i></td>
<td width="116">&nbsp;</td>
</tr>
<tr>
<td><span class="bodytext">Date posted:</span><span class="bodytext6">
<?= $uRow[3]?>
<input type="hidden" name="nid" value="<?= $uRow[4]?>">
</span></td>
<td width="116"><input name="delete" type="submit" value="Delete Feedback" onclick="return confirmSubmit()" /></td>
</tr>
<tr>
<td colspan="2" class="bodytext"> -----------------------------------------------------------------------------</td></tr></table></td></tr>
<?
}
}
?>
</table></form></td></tr></table></td></tr></table>
Link to comment
https://forums.phpfreaks.com/topic/5754-delete-query-in-sql/#findComment-20606
Share on other sites

guys,

i think the second page (feedbackdelete.php) is working.
the problem is on the first page (f#@k!) its late that i noticed
that i has already deleted 100 of of 250 items on my database because its deleting
the wrong item. what i mean is,
let say i was supposed to delete item with an id of 104, id 104 will not be deleted
instead id 45 is deleted
i also tried clicking on the other delete button and its deleting the same id (45)
instead of its respective ids.

this is the script on my first page
==========
<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("Do you really want to delete this?");
if (agree)
return true ;
else
return false ;
}
-->
</script>
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="455"><table width="624" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="624"><?
include '../db_connect.php';

$uSql = "SELECT news_title, news_content, news_sender, news_date, newsid FROM news ORDER by news_date DESC";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
echo 'no data found';
}
else{
while($uRow = mysql_fetch_row($uResult)){

?>
<table width="610" border="1" cellspacing="0" cellpadding="0">
<form name="frmnews" method="POST" action="feedbackdelete.php">
<tr>
<td width="606"><table width="612" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="481" class="bodytext3"><?= $uRow[0]?> </td>
<td width="116">&nbsp;</td>
</tr>
<tr>
<td><span class="bodytext">Message:</span><span class="bodytext6">
<?= $uRow[1]?>
</span></td>
<td width="116">&nbsp;</td>
</tr>
<tr>
<td><span class="bodytext">Sender:</span> <i><span class="bodytext6">
<?= $uRow[2]?>
</span></i></td>
<td width="116">&nbsp;</td>
</tr>
<tr>
<td><span class="bodytext">Date posted:</span><span class="bodytext6">
<?= $uRow[3]?>
<input type="hidden" name="nid" value="<?= $uRow[4]?>">
</span></td>
<td width="116"><input name="delete" type="submit" value="Delete Feedback" onclick="return confirmSubmit()"></td>
</tr>
<tr>
<td colspan="2" class="bodytext"><img src="../images/spacer.gif" width="10" height="15" /></td></tr></table></td></tr>
<?
}
}
?>
</form></table> </td>
</tr>
</table></td>
</tr>
</table>
=========

need help please!!!

thanks!!
Link to comment
https://forums.phpfreaks.com/topic/5754-delete-query-in-sql/#findComment-20659
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.