Sooth Posted November 1, 2007 Share Posted November 1, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/75652-solved-news-update/ Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 can you echo the query $query="UPDATE news SET title='$_POST[title]', content='$_POST[content]' WHERE id='$_GET[n]'"; echo $query; Quote Link to comment https://forums.phpfreaks.com/topic/75652-solved-news-update/#findComment-382811 Share on other sites More sharing options...
Sooth Posted November 1, 2007 Author Share Posted November 1, 2007 can you echo the query $query="UPDATE news SET title='$_POST[title]', content='$_POST[content]' WHERE id='$_GET[n]'"; echo $query; Yes. I can echo the query. It looks OK. Quote Link to comment https://forums.phpfreaks.com/topic/75652-solved-news-update/#findComment-382826 Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 here is your error @mysql_select_db($db_error); ?? should be @mysql_select_db($db_database); Quote Link to comment https://forums.phpfreaks.com/topic/75652-solved-news-update/#findComment-382830 Share on other sites More sharing options...
Sooth Posted November 1, 2007 Author Share Posted November 1, 2007 here is your error @mysql_select_db($db_error); ?? should be @mysql_select_db($db_database); LOL Thanks, man. Quote Link to comment https://forums.phpfreaks.com/topic/75652-solved-news-update/#findComment-382862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.