doctortim Posted December 27, 2007 Share Posted December 27, 2007 Hi there Now working on my blogs update page, that is the page receiving the contents of the update form (from the edit page), and giving the sql query to update the entry in the database. My code looks like this: <?php include_once("include/connect_sql.inc.php"); ?> <?php // Retreiving Form Elements from Form $thisArticle_id = addslashes($_POST['article_id']); $issue_no = addslashes($_POST['issue_no']); $issue_date = addslashes($_POST['issue_date']); $focus = addslashes($_POST['focus']); $toc = addslashes($_POST['toc']); $article = addslashes($_POST['article']); $sqlQuery = "UPDATE blogprofessional SET issue_no = '$issue_no' , issue_date = '$issue_date' , focus = '$focus' , toc = '$toc' , article = '$article' WHERE article_id = '".$thisArticle_id."';"; $result = mysql_query($sqlQuery); ?> When I check the database nothing has been updated. I even put a hidden text field in the edit form so it contains the article id, which is then passed with the form to the update page. That way I am able to define the variable $thisArticle_id. Why isn't this update query executing correctly???? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/ Share on other sites More sharing options...
papaface Posted December 27, 2007 Share Posted December 27, 2007 _id = '".$thisArticle_id."';"; should be _id = '".$thisArticle_id."'"; Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424184 Share on other sites More sharing options...
suttercain Posted December 27, 2007 Share Posted December 27, 2007 You have a semi colon that should not be there... Change $sqlQuery = "UPDATE blogprofessional SET issue_no = '$issue_no' , issue_date = '$issue_date' , focus = '$focus' , toc = '$toc' , article = '$article' WHERE article_id = '".$thisArticle_id."';"; to $sqlQuery = "UPDATE blogprofessional SET issue_no = '$issue_no' , issue_date = '$issue_date' , focus = '$focus' , toc = '$toc' , article = '$article' WHERE article_id = '".$thisArticle_id."'"; Also add the mysql error to see what's happening if an error is returned. $result = mysql_query($sqlQuery) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424185 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 Change $result = mysql_query($sqlQuery); to $result = mysql_query($sqlQuery) or die ('Error in query: $query. ' . mysql_error()); Also, you can change WHERE article_id = '".$thisArticle_id."';"; to WHERE article_id = '$thisArticle_id'"; Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424186 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 BTW, there is nothing wrong with having an extra semi colon in your SQL Query, but it's not required. Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424187 Share on other sites More sharing options...
papaface Posted December 27, 2007 Share Posted December 27, 2007 Erm... Is there an echo in here? (and not the php kind) I've already stated the problem in the first reply, was it necessary to say the same thing essentially two more times? Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424188 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 It sure was. Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424189 Share on other sites More sharing options...
doctortim Posted December 27, 2007 Author Share Posted December 27, 2007 cool I'll try those changes... and by the way I was happy to see a whole heap of quick replies for once. More the better. Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424190 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 You'll find the Error part will be the most helpful, since the semi colon is probably not your problem. Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424192 Share on other sites More sharing options...
doctortim Posted December 28, 2007 Author Share Posted December 28, 2007 I made all those changes and it still isn't inserting the updated info. It isn't even showing an sql error. Anyone can help? Anything else I can try? Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424553 Share on other sites More sharing options...
corbin Posted December 28, 2007 Share Posted December 28, 2007 Try echoing out the query somewhere and tell us what it says. And just for the record, like revraz said, semicolon's on SQL statements are not incorrect. A semi colon on a SQL statement is just like in PHP... It ends the command. In SQL files, for example, you might have 40 different queries, and without semi colons, the entire file would syntax error. (In PHP, as a security 'feature' you're only able to send 1 query at a time.) Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424558 Share on other sites More sharing options...
doctortim Posted December 28, 2007 Author Share Posted December 28, 2007 This is what I got UPDATE blogprofessional SET issue_no = 'sdf2 tim' , issue_date = 'sdg' , focus = 'sdggsdgfsgsfg gf g fgfg' , toc = 'gs f dfggg gdbg' , article = 'gfgfgdgsg fggfg gd g gg g g g ' WHERE article_id = '' Does this mean the article_id is empty?? I was getting a hidden text field to post it to this page Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424562 Share on other sites More sharing options...
corbin Posted December 28, 2007 Share Posted December 28, 2007 Yes that means $thisArticleId is empty. Try looking at your form to make sure the field is named 'article_id'.... And make sure it has a value by viewing the html source. Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424564 Share on other sites More sharing options...
doctortim Posted December 28, 2007 Author Share Posted December 28, 2007 Yeah the name and id are both set to "article_id" The text input where the article_id number is placed (so that it gets passed to the update page) is a hidden field. Therefore its not showing up in the source, could this also be why its not being included as an element in the POST array? Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424570 Share on other sites More sharing options...
revraz Posted December 28, 2007 Share Posted December 28, 2007 Post the form. Quote Link to comment https://forums.phpfreaks.com/topic/83379-update-query-not-working/#findComment-424648 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.