View Single Post
Old 04-11-2005   #12 (permalink)
ViciOuS
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Well, I kinda scrapped the old delete.php and made a new script that does both edit and delete. But once again i'm having troubles. Could it be because of the GET variable is bringing me false info?


Ok, this is what i've got for my EditNews_interface.php

Code:
<?php 
include('mysql_connect.php');

$sql = mysql_query("SELECT * FROM news ORDER BY id DESC");

while($row = mysql_fetch_array($sql))
{
?> 


<html><head><title></title>
<style>
<!--
a{text-decoration:none}
//-->
</style>
<style>
a:visited{color:blue; text-decoration:none; }
a:active{color:red; text-decoration:none; }
a:link{color:red; text-decoration:none; }
a:hover{color:orange; text-decoration:underline; }
</style>
</head>
<BODY background="../images/image_22.gif">
<div align="left">
 <TABLE width="100%" border="0" cellspacing="0" cellpadding="3">
   <tr> 
     <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<?php echo $row['title'] . ' | Posted by: ' . $row['name'] . ' on ' . $row['date'] . ' ID# ' . $row['id']; ?></font></b>
     </td>
   </tr>
   <tr>
     <td>
      <?php echo "[ <a href=\"EditNews.php?id=\$id\">Edit Post</a> ] [ 
      <a href=\"DelNews.php?id=\$id\">Delete Post</a> ]"; ?>
     </td>
     <br>
   </tr>
 </TABLE>
</div>
</body>
</html>

<?php
}
?>
My DeleteNews.php
Code:
<?php
session_start();

// Define session and password variables
$pw = $_SESSION['password'];
$ad_pw = "******";
$enpw = md5($ad_pw);

// Check to see if they are logged in..
if ($enpw != $pw){
header("Location: Loggedin.php");

}else{

include('mysql_connect.php');

$id = $_GET['id'];

 if(isset($id)) {
mysql_query("DELETE FROM news WHERE id='$id'") or die("Could not delete news post"
 . mysql_error());
}else{
   echo 'Deletion of news failed, system error, no id specified...';
}
}
?>
EditNews.php
Code:
<?php

include('mysql_connect.php');

$ID = $_GET['id'];

$sql = mysql_query("SELECT * FROM news WHERE id='$ID'");
$row = mysql_fetch_object($sql);
?>

<div align="center">
  <TABLE width="80%" valign="center">
    <tr bgcolor="#EEEEEE">
      <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
&nbsp;News: </td>
      <td><TEXTAREA Name="news" Rows="15" Cols="55"><?php echo $row->news; ?></TEXTAREA></td>
    </tr>
  </TABLE>
  <TABLE width="80%" valign="center">
    <tr bgcolor="#CCCCCC">
     <td><center>
        <INPUT type="submit" tabindex="5" name="submit" value="Add News">
       </center></td>
    </tr>
  </TABLE>
[ <a href="Loggedin.php" target="iframe">Back to Admin CP</a> ]
</div>
And finally, my Handle_EditNews.php
Code:
<?php
include('mysql_connect.php');

$news = $_POST['news'];
$ID = $_GET['ID'];

 if(!isset($ID)) {
echo 'A system error occured and the editing was unable to finish';

}else{
$worked = mysql_query("UPDATE news SET news='$news' WHERE id='$ID'");

 if(!$worked) {
   die('Didn\'t work because' . mysql_error());
}else{
   echo 'You have successfully updated the news.';
}
}
?>

I've still got a AddNews.php and a news.php but those are working fine. It's just, my EditNews_interface.php page is not working properly. The Edit links all have the same url, and same as the delete links.

When i click an edit link, it takes me to my editnews page but theres nothing in the textarea, and when i click on a delete link, it takes me to a blank page in my iframe.. not even an error
ViciOuS is offline