Jump to content


Photo

Edit News Help


  • Please log in to reply
4 replies to this topic

#1 Guteman

Guteman
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • LocationWisconsin

Posted 26 May 2006 - 01:02 AM

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]

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 26 May 2006 - 01:44 AM

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"])


Life's too short for arguing.

#3 Guteman

Guteman
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • LocationWisconsin

Posted 26 May 2006 - 09:33 PM

still not working

#4 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 26 May 2006 - 09:44 PM

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"];

NoGray.com


#5 Guteman

Guteman
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • LocationWisconsin

Posted 26 May 2006 - 11:59 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users