0

I am trying to pass a variable to a mysqli query as shown below but it never updates the record

This works:

mysql> UPDATE zeus.alldata SET A='56.1' WHERE wwxRecord = 
(SELECT max(dateTime) FROM wwx.wmx_archive);
Query OK, 1 row affected (0.17 sec)
Rows matched: 1  Changed: 1  Warnings: 0

This does not:

$A = "56.1";
$sql = mysqli_query($conn,"UPDATE ".$template_db.".alldata SET A='$A' 
WHERE wwxRecord = (SELECT max(dateTime) FROM ".$wwx_db.".wmx_archive");

This does not:

$A = "56.1";
$sql = mysqli_query($conn,"UPDATE ".$template_db.".alldata SET A=".$A." 
WHERE wwxRecord = (SELECT max(dateTime) FROM ".$wwx_db.".wmx_archive");

Using an echo $A; right before and after the statement show the correct 56.1, but nothing I seem to try allows me to pass the $A to the query. The other variables work fine (".$template_db.") as I use them throughout the script for other database updates.

I hope I am just missing something simple!

2
  • if ( !$sql ) trigger_error( mysqli_errno($conn) . ' '. mysqli_error($conn), E_USER_ERROR); What does that print? Commented Mar 30, 2016 at 16:48
  • Are you executing all queries on the same system or 1st on local and other one on live? Commented Mar 30, 2016 at 16:54

1 Answer 1

1

You are missing the ending ) of mysqli_query() function

$A = "56.1";
$template_db = "zeus";
$wwx_db = "wwx";

$sql_string = "UPDATE ".$template_db.".alldata SET A='$A' 
WHERE wwxRecord = (SELECT max(dateTime) FROM ".$wwx_db.".wmx_archive)";

$sql_query = mysqli_query($conn,$sql_string);
Sign up to request clarification or add additional context in comments.

1 Comment

Wow...amazing...I must have looked at that thing for an hour and missed the missing ')'. Thank you!! It is working perfectly now!

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.