ecabrera Posted December 20, 2011 Share Posted December 20, 2011 some how i cant update i dont know y <div id="ahome"> <?php include "scripts/connect.php"; if(isset($_GET[edit])){ $newid = $_GET['edit']; $query = mysql_query("SELECT * FROM news WHERE id='$newid' LIMIT 1"); $rows = mysql_fetch_array($query); $newstitle = stripslashes($rows['title']); $newsby = stripslashes($rows['by']); $newsbody = stripslashes($rows['body']); } ?> <?php if ($_POST['saveedit']){ $newid = mysql_real_escape_string($_POST['saveedit']); $newstitle = mysql_real_escape_string($_POST['title']); $newsby = mysql_real_escape_string($_POST['by']); $newsbody = mysql_real_escape_string($_POST['body']); if ($newstitle && $newsby && $newsbody){ $query = mysql_query("UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'"); echo "UPDATE SUCCESFULLY!"; }else $msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>"; } ?> <form action='enews.php' method='POST'> <table> <tr> <td></td> <td><?php echo $msg; ?></td> </tr> <tr> <td>Article Title</td> <td><input type='text' name='title' size='45' value='<?php echo $newstitle; ?>'/></td> </tr> <tr> <td>By:</td> <td><input type='text' name='by' size='30' value='<?php echo $newsby; ?>' /></td> </tr> <tr> <td>Article Body</td> <td><textarea cols='45' rows='25' name='body'><?php echo stripslashes($newsbody); ?></textarea></td> </tr> <tr> <td><input type='hidden' name='saveedit' value='$newid'/></td> <td><input type='submit' name='updatebtn' value='Update' /></td> </tr> </table> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/ Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 Are you getting any errors? Try removing the php tags here } ?> <?php if ($_POST['saveedit']){ Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299806 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 no i dont get erros and i did but its not working Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299809 Share on other sites More sharing options...
floridaflatlander Posted December 20, 2011 Share Posted December 20, 2011 I don't do it like you, I always gave the query two parameters, $query = mysql_query(dbc, "UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'"); Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299811 Share on other sites More sharing options...
AyKay47 Posted December 20, 2011 Share Posted December 20, 2011 I don't do it like you, I always gave the query two parameters, $query = mysql_query(dbc, "UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'"); actually, the second parameter is the link_identifier, the first parameter is the query. OP, have you tried to debug this at all yet? I would start there. Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299812 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 Change: if ($_POST['saveedit']){ To: if(isset($_POST['updatebtn'])) Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299813 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 nothing i dont get any errors and i dont whats the problem Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299814 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 Set up error reporting. Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299816 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 i still get nothing i //show warnings and errors error_reporting(E_ERROR | ERROR_WARNING); //show all types but notices error_reporting(E_ALL ^ E_NOTICE); i try this and nothing Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299818 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 So, does it do noting at all, or does it update your database with no values? Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299820 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 You want to show all warnings, errors, notices, everything while developing. error_reporting(-1); ini_set('display_errors', 'On'); Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299822 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 i get this Notice: Undefined variable: msg in /home/website/public_html/enews.php on line 63 but i dont think thats the problem and melloorr i go to the page to edit and i when im done editing and press update it looks like everything i edit stays there but when i click to another link and come back its still there Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299824 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 Copy and paste this. If it doesn't work then I have no clue what could be the problem <div id="ahome"> <?php include "scripts/connect.php"; if(isset($_GET[edit])){ $newid = $_GET['edit']; $query = mysql_query("SELECT * FROM news WHERE id='$newid' LIMIT 1"); $rows = mysql_fetch_array($query); $newstitle = stripslashes($rows['title']); $newsby = stripslashes($rows['by']); $newsbody = stripslashes($rows['body']); } if(isset($_POST['updatebtn'])){ $newid = $_POST['saveedit']; $newstitle = $_POST['title']; $newsby = $_POST['by']; $newsbody = $_POST['body']; if ($newstitle != '' && $newsby != '' && $newsbody != ''){ $query = mysql_query("UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'"); echo "UPDATE SUCCESFULLY!"; }else $msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>"; } ?> <form action='enews.php' method='POST'> <table> <tr> <td></td> <td><?php echo $msg; ?></td> </tr> <tr> <td>Article Title</td> <td><input type='text' name='title' size='45' value='<?php echo $newstitle; ?>'/></td> </tr> <tr> <td>By:</td> <td><input type='text' name='by' size='30' value='<?php echo $newsby; ?>' /></td> </tr> <tr> <td>Article Body</td> <td><textarea cols='45' rows='25' name='body'><?php echo stripslashes($newsbody); ?></textarea></td> </tr> <tr> <td><input type='hidden' name='saveedit' value='$newid'/></td> <td><input type='submit' name='updatebtn' value='Update' /></td> </tr> </table> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299825 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 Nope it doesnt work Thnaks for helping Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299827 Share on other sites More sharing options...
AyKay47 Posted December 20, 2011 Share Posted December 20, 2011 debug your query. $query = mysql_query("UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299828 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 i get this You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by='Edward Jobs', body='While the PlayStation 3 is just now hitting its stride, ' at line 1 what does it mean Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299830 Share on other sites More sharing options...
floridaflatlander Posted December 20, 2011 Share Posted December 20, 2011 i get this Notice: Undefined variable: msg in /home/website/public_html/enews.php on line 63 is this line 63? $msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>"; Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299831 Share on other sites More sharing options...
AyKay47 Posted December 20, 2011 Share Posted December 20, 2011 i get this You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by='Edward Jobs', body='While the PlayStation 3 is just now hitting its stride, ' at line 1 what does it mean "by" is a mysql reserved words, which means that you have to wrap the column name in backticks when using in a query, or rename the column. $query = mysql_query("UPDATE news SET title='$newstitle', `by`='$newsby', body='$newsbody' WHERE id='$newid'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299832 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 AyKay47 it remove that but it still wont update Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299833 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 floridaflatlander has a point. i get this Notice: Undefined variable: msg in /home/website/public_html/enews.php on line 63 is this line 63? $msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>"; That will not display it to the screen, it should be: $msg ='<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>'; echo $msg; Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299836 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 The echo is later in the code, presumably so it is displayed at the right place in the page. Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299837 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 i have it here <td><?php echo $msg; ?></td> Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299838 Share on other sites More sharing options...
melloorr Posted December 20, 2011 Share Posted December 20, 2011 The echo is later in the code, presumably so it is displayed at the right place in the page. But it is displayed in the form, which has to be sent before the variable gets defined Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299839 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 The error is due to the fact that the variable is only initialized in the event that one of the fields is left empty. It should be initialized as empty if there is no error, or it should be checked for a value before the echo, but that isn't related to the failure to update problem. Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299840 Share on other sites More sharing options...
ecabrera Posted December 20, 2011 Author Share Posted December 20, 2011 Pikachu2000 is right this has nothing to do with update problem i tred checking my code alot of times but i can figure it out when i update it says update succesfull but it doesnt even updates Quote Link to comment https://forums.phpfreaks.com/topic/253558-update/#findComment-1299842 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.