Having delete problems...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yo matey
Forum Newbie
Posts: 1
Joined: Mon Feb 03, 2003 10:15 am

Having delete problems...

Post by yo matey »

Okay, I have a post news script that I made. However I wish to be able to delete the news with a link at the bottom of each one. Here is my script, and if you can tell me whats wrong, it would be appriciated. Thanks.

Code: Select all

<?include "header.phtml"?>

<?php

// Create Connection
$connection = mysql_connect("localhost","USERNAME","PASSWORD") or die ("Couldn't Connect to Server");

// Select Database
$db = mysql_select_db("hb", $connection) or die ("Couldn't Connect to DB");
 
// Create SQL Statement
$sql = "SELECT name, date, title, story, id  FROM Stories order by date desc" or die ("Couldn't SQL");

// Execute Search and Result
$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query");

// Start Results Formatting
// echo "<TABLE bgcolor=black BORDER = 0 WIDTH=100%>";

// Format Results
while ($row = mysql_fetch_array($sql_result) ) &#123;

$name = $row&#1111;name];
$title = $row&#1111;title];
$story = $row&#1111;story];
$date = date("D F, Y",$row&#1111;date]); 
$id = $row&#1111;id];



echo <<<EOT

<b>User:</b> $name

<br><b>Date:</b> $date<br>


<b>Title:</b> $title

<br>
<b>Journal Entry from:</b> $name<br><br>$story<br><a href=viewstorydelete.phtml?B=C&id=$id>Delete</a><hr width="100%" size="1" color="#3B6A8A"><br>

</font>
</center> 

EOT;

 &#125;


// Close Formatting

If($B == "C") &#123; 
                  $sql2 = mysql_query( "DELETE FROM Stories WHERE id = '$id'");
 

    &#125;  



?>


<?include "footer.phtml"?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

could be

Post by phpScott »

I am assuming that the page you have shown us is called showstoreydelete.phtml.

I which case the href link looks correct but when the link is clicked your $id gets changed when you run through the top of the page agian.

And besides B will always equal C.

If you wan the script all on one page you will have to do your checking for B equal to C and do your delete of id before you start reassign different values to id.

phpScott
Post Reply