0

i am trying to figure out the syntax problem in my query the block of code goes like this:

$updatequery = "update patient_dim set dentist_id = $dentist_id where".
                "patient_id = $patient_id";
$queryResult = mysql_query($updatequery,$con);

if(!$queryResul){
      trigger_error("insert error" . mysql_error());
}

mysql_close($con);

then the error goes like this:
Notice: inssert errorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\"1" where patient_id = 4'

i suspect incorrect syntax in the $updatequery statement

for further information value of the $patient_id = 1 while the value of the $dentist_id = 4, i have tried all of your approaches still the same error. anyway thanks your helping

3
  • give a space after where condition Commented Apr 22, 2015 at 8:49
  • Do not use deprecated mysql_* API. Use mysqli_* or PDO and learn about prepared statements. Commented Apr 22, 2015 at 8:51
  • To troubleshoot an error like this normally you would output your query to a string and try to execute it manually. Doing this would highlight, as @AbhikChakraborty noted, you are missing a space. Commented Apr 22, 2015 at 9:00

3 Answers 3

1

Your query needs space after where

$updatequery = "update patient_dim set dentist_id = $dentist_id where patient_id = $patient_id";
Sign up to request clarification or add additional context in comments.

2 Comments

still does not work, same error with the syntax, all values of the variable is correct
Can you update your question with echoed value of query
1
$updatequery = "update patient_dim set dentist_id = $dentist_id where".
            " patient_id = $patient_id";

you forgot to add space after WHERE clause

1 Comment

I would go as far to say you might as well remove the concatenation and just have one, one line, query string ("update patient_dim set dentist_id = $dentist_id where patient_id = $patient_id")
0

After WHERE Clause there must be a blank space before the condition. Use as follows.

<?php
    $updatequery = "update patient_dim set dentist_id = ".$dentist_id ." where patient_id = ".$patient_id;
    $queryResult = mysql_query($updatequery);
    if(!$queryResult){
         die("insert error" . mysql_error());
    }

    mysql_close($con);
?>

3 Comments

i tred your approach and still the same error, and all variables has the correct value
echo $updatequery and try to execute the query in SQL Editor(PhpMyadmin),It will help you to catch the error.Can you please change the variables in if statement from $queryResul to $queryResult (It is a typo Mistake).I am editing the query,Please try again.
i already figure out the typo , there's a mistyped / in the other parts of the code. anyway thank you helping out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.