Jump to content

[SOLVED] news update


Sooth

Recommended Posts

Hi! I made this code to edit news on an website. The query looks OK, but it is not updating the news.

 

<?php
session_start();
include "config.inc.php";
include "header.inc.php";
?>

<h1>Admin » News » Edit</h1>
<?php
if($_SESSION[admin]) {
?>
<?php include "admin_menu.inc.php"; ?>
<?php
if($_POST[e]) {
mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_error); 
$query="UPDATE news SET title='$_POST[title]', content='$_POST[content]' WHERE id='$_GET[n]'";
mysql_query($query);
mysql_close();
echo "<p>News updated.</p>";
}
else {
mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database)or die($db_error);
$query="SELECT * FROM news WHERE id='$_GET[n]'";
$result=mysql_query($query);mysql_close();
while($row=mysql_fetch_array($result))
{?>
<form action="<?php echo $site_address; ?>admin/news/edit/<?php echo $_GET[n]; ?>/" method="post">
<p>Title</p>
<p><input type="text" name="title" value="<?php echo $row[title]; ?>" style="width: 200px;" /></p>
<p>Content</p>
<p><textarea name="content" cols="100" rows="10"><?php echo $row[content]; ?></textarea></p>
<p><input type="hidden" name="e" value="1" /><input type="submit" value="OK" /></p>
</form>
<?php
}
}
}
else echo "<p>You must be an Administrator to view this page.</p>";
?>

<?php
include "footer.inc.php";
?>

 

The URLs are rewritted and ...news/edit/xxxx/ becomes ...edit.php?n=xxxx, so the problem isn't at the $_GET[n] neither.

 

I've made a similar page to write news and it works perfectly.

 

What could be wrong?

Link to comment
https://forums.phpfreaks.com/topic/75652-solved-news-update/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.