Mystixs Posted May 14, 2007 Share Posted May 14, 2007 Lol, I think I am becoming a regular member here. I keep running into problems.Anyway, I have been working on my news system and now I am trying to edit the news. But it's not working. Here is my code: if ($_GET['action']=="editnews") { $result = mysql_query("SELECT * FROM news WHERE id=$_GET[id]"); while($row = mysql_fetch_array($result)) echo '<form action="admin.php?page=news&action=editnews2" method="post">'; echo 'Title: <input type="text" name="title" value="' . $row['name'] . '"/>' ."<br />"; echo 'Date: <input type="text" name="date" value="' . $row['date'] . '"/>' ."<br />"; echo 'Message: <input type="text" name="message" size="100" value="' . $row['message'] . '"/>' ."<br />"; echo '<input type="submit" />'; echo '</form>'; }if ($_GET['action']=="editnews2") { $result = mysql_query("SELECT * FROM news WHERE id=$_GET[id]"); while($row = mysql_fetch_array($result)) mysql_query("INSERT INTO news VALUES ('NULL', '$_POST[name]', '$_POST[date]', '$_POST[message]')"); } It runs everything right, just doesn't do anything to the news... Link to comment Share on other sites More sharing options...
justsomeguy Posted May 14, 2007 Share Posted May 14, 2007 What are you trying to do? The logic doesn't make sense. The code on the bottom (editnews2) gets everything from the database for a certain ID, and then for each thing it finds in the database it inserts a new item with a null ID. I don't know what you're trying to do, but I don't think that code is doing what you are expecting. Link to comment Share on other sites More sharing options...
Mystixs Posted May 14, 2007 Author Share Posted May 14, 2007 Hmm Forgot to do some things. But didn't help. Here is new code: if ($_GET['action']=="editnews") { $result = mysql_query("SELECT * FROM news WHERE id=$_GET[id]"); while($row = mysql_fetch_array($result)) echo '<form action="admin.php?page=news&action=editnews2" method="post">'; echo 'Title: <input type="text" name="title" value="' . $row['name'] . '"/>' ."<br />"; echo 'Date: <input type="text" name="date" value="' . $row['date'] . '"/>' ."<br />"; echo 'Message: <input type="text" name="message" size="100" value="' . $row['message'] . '"/>' ."<br />"; echo '<input type="submit" />'; echo '</form>'; }if ($_GET['action']=="editnews2") { mysql_query("UPDATE news SET name='$_POST[name]' date='$_POST[date]' message='$_POST[message]'"); } Anyway, it still wont work. It doesn't effect the news post at all... Link to comment Share on other sites More sharing options...
justsomeguy Posted May 14, 2007 Share Posted May 14, 2007 That update query will update the entire news table to all be the same. If you want to update a specific record, use a WHERE clause in the update statement. You also need to escape all of the inputs in the query using mysql_real_escape_string. Also check mysql_error to see if you're getting an error during the update query. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.