MrGarcia Posted April 21, 2010 Share Posted April 21, 2010 hi.. i have here the "edit_news.php" to edit my news in my site.. it is connected to database.. the first time i try editing.. its working.. but now.. if i edit the news, the text didn't change.. here's my code inside edit_news.phpp <?php include("config.php"); if(isset($_POST['submit'])) { // Set global variables to easier names // and prevent sql injection and apostrophe to break the db. $title = mysql_escape_string($_POST['title']); $text1 = mysql_escape_string($_POST['text1']); $text2 = mysql_escape_string($_POST['text2']); $result = mysql_query("UPDATE news SET title='$title', text1='$text1', text2='$text2' WHERE newsid='$newsid' ",$connect); echo "<b>Thank you! News UPDATED Successfully!"; echo "<meta http-equiv=Refresh content=2;url=admin.php>"; } elseif(isset($_GET['newsid'])) { $result = mysql_query("SELECT * FROM news WHERE newsid='$_GET[newsid]' ",$connect); while($myrow = mysql_fetch_assoc($result)) { $title = $myrow["title"]; $text1 = $myrow["text1"]; $text2= $myrow["text2"]; ?> <br> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="newsid" value="<? echo $myrow['newsid']?>"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="17%">Title : </td> <td width="83%"><input name="title" type="text" size="30" value="<? echo $title; ?>"></td> </tr> <tr> <td>Message : </td> <td><textarea name="text1" cols="35" rows="10"><? echo $text1; ?></textarea></td> </tr> <tr> <td>Message2 : </td> <td><textarea name="text2" cols="35" rows="10"><? echo $text2; ?></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Update News"></td> </tr> </table> </form> <? }//end of while loop }//end else ?> Quote Link to comment https://forums.phpfreaks.com/topic/199213-cant-update-the-item-inside-database/ Share on other sites More sharing options...
mrMarcus Posted April 21, 2010 Share Posted April 21, 2010 too little information for me to do anything about your problem. you gotta think out your questions before posting, and give as much information as possible regarding your issue. i do notice some old code in your script that you should update to get into compliance with new versions of PHP. use full tags instead of short tags: change <? to <?php in all cases. and use $_SERVER variable in this, and all instances like it: $PHP_SELF to $_SERVER['PHP_SELF'] honestly, you're better to remove that from your form action altogether, and just leave it blank, ie. action="" also, stay consistent with your variables; you are using single and double quote, and in some cases, no quotes at all which will make PHP assume that variable is a constant, discover that it is not, and try and convert it to a string. use single quotes over double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/199213-cant-update-the-item-inside-database/#findComment-1045550 Share on other sites More sharing options...
I-AM-OBODO Posted April 21, 2010 Share Posted April 21, 2010 Just like mrMarcus explained, try to make your tag consistant with what's in vogue. You could use a saparate page for your html form and your php script in a separate page to make your job much neater and simpler. Quote Link to comment https://forums.phpfreaks.com/topic/199213-cant-update-the-item-inside-database/#findComment-1045578 Share on other sites More sharing options...
MrGarcia Posted April 21, 2010 Author Share Posted April 21, 2010 i did every you said.. but why is it.. the first time i try the editing.. its updating my database.. and display the new and edited news in my news.php but now.. i dunno why i got this problem... btw.. here's my example screenshot.. here's my latest news.. http://www.mrgarcia.co.cc/filphotos/pictures/f0c32d18043f2b782c76b61da16c07c0.png i would like to edit it.. http://www.mrgarcia.co.cc/filphotos/pictures/060448aef6d46eb5fe60dfa7f1997305.png after editing it.. i submit it.. http://www.mrgarcia.co.cc/filphotos/pictures/129ff82c9939bcee3366c33978bc5855.png and the results still the same.. http://www.mrgarcia.co.cc/filphotos/pictures/f0c32d18043f2b782c76b61da16c07c0.png [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/199213-cant-update-the-item-inside-database/#findComment-1045584 Share on other sites More sharing options...
MrGarcia Posted April 21, 2010 Author Share Posted April 21, 2010 anyone here? Quote Link to comment https://forums.phpfreaks.com/topic/199213-cant-update-the-item-inside-database/#findComment-1045644 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.