Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/83379-update-query-not-working/
Share on other sites

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());

 

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

 

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.)

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

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.