Jump to content

Archived

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

Guteman

Edit News Help

Recommended Posts

I am making my own news script, but I seem to be stuck with this code trying to edit the news Im not getting Information updated echo.

here is the code.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<form action=admin-news.php method="post">
<input type="hidden" name="cmd" value="edit">

<table width=325 cellspacing=0 cellpadding=0 border=0 align=center>
<tr><td>Title:</td><td><input type="text" name="title" value="<?php echo $myrow["title"] ?>" size=30></td></tr>
<tr><td>Story:</td><td><textarea name="story" rows=5 cols=20><?php echo $myrow["story"] ?></textarea></td></tr>
<tr><td>Author:</td><td><input type="text" name="author" value="<?php echo $myrow["author"] ?>" size=30></td></tr>
<input type="hidden" name="cmd" value="edit">
<tr><td colspan=2 align=center><br><input type="submit" name="submit" value="Submit"></td></tr>
</table>
</form>

<?php


}

if ($_POST["$submit"])

{
$id = $_GET["id"];
$title = $_POST["title"];
$story = $_POST["story"];
$author = $_POST["author"];

mysql_query("UPDATE news SET title='$title' , story='$story' , author='$author' WHERE ID='$id'");

echo ("Thank you! Information updated.");

}
}
?> [/quote]

Share this post


Link to post
Share on other sites
if ($_POST["$submit"])

should change to

if ($_POST['submit'] == 'submit')
or
if (isset($_POST['submit']))

I prefer the first one, it's safer.

your old code would be fine if you define $submit before the if statement. like:

$submit = 'submit';

if ($_POST["$submit"])

Share this post


Link to post
Share on other sites
You are not submitting the news id in your form "WHERE ID='$id'" add the id as a hidden filed and change
$id = $_GET["id"];
to
$id = $_POST["id"];

Share this post


Link to post
Share on other sites
fixed it, for some reason when I made my table for the mysql, I made it ID not id.. so it messed with alot of the coding I did.

Share this post


Link to post
Share on other sites

×

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.