$column = "`0907001`='0',`0907002`='0',`0907003`='0',`0907004`='0',`0907005`='0'";
$date="01/01/2013";
$sql_cmd = "UPDATE `$database`.`$table` SET ($column) WHERE `$table`.`Date` = '$date'";
if(!mysql_query($sql_cmd)) {
die('inside AddUserToDataBase Error: ' . mysql_error());
}
Here I got an error
the error is
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 '(`0907001`='0',`0907002`='0',`0907003`='0',`0907004`='0',`0907005`='0') WHERE `C' at line 1
Please Help....
How can I solve this problem........
Just drop the ( ) around $columns in the query:
$sql_cmd = "UPDATE `$database`.`$table` SET $column WHERE `$table`.`Date` = '$date'";
Remove the parenthesis around the columns. Instead of:
UPDATE TABLE table SET (column = value)
It should be
UPDATE TABLE table SET column = value
Related
I have 2 database that link together. I need to retrieve data from that table and insert those column into a table in different database based on their Unique id number.
<?php
$handle = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_query("USE shop",$handle);
$query = "SELECT ModelCode,Class FROM shopfloor_pro WHERE CommNo = '0985560712'";
$result = mysql_query($query);
while ($data = mysql_fetch_object($result)){
$variable1 = $data->ModelCode;
$variable2 = $data->Class;
mysql_query("USE vt",$handle);
$sql = "INSERT INTO track SET
t_model_code = '$variable1',
t_class = '$variable2' WHERE t_comm_no = '0985560712'";
if (!mysql_query($sql)) {
echo '<p>Error adding data into database: ' . mysql_error() . '</p>';
}
mysql_query("USE paintshop",$handle);
}
?>
this is the data that i want to retrieve
this is where i want to put the data
When i run the code it shows
"Error adding data into database: 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 'WHERE t_comm_no = '0985560712'' at line 3"
You can most likely do this in a single query - but as pointed out the mysql api has been deprecated a long time ago and totally removed from PHP 7+.
To do the query in a single operation you might try like this:
insert into `vt`.`track` (`t_model_code`,`t_class` )
select `ModelCode`,`Class` from `shop`.`shopfloor_pro` where `CommNo`='0985560712'
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
Your query needs space after where
$updatequery = "update patient_dim set dentist_id = $dentist_id where patient_id = $patient_id";
$updatequery = "update patient_dim set dentist_id = $dentist_id where".
" patient_id = $patient_id";
you forgot to add space after WHERE clause
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);
?>
I get an error with my PHP code when updating the table patient. I cannot find the problem.
Here is my error:
Verification Error: 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 '1' at line 1
<?php
$edit = mysql_query("UPDATE `patient` SET `date`='$date', `fname`='$fname', `lname`='$lname', `birthday`='$dob', `address`='$address', `work`='$work', `civil`='$civil', `gender`='$sex', `btype`='$bloodtype', `height`='$hgt', `weight`='$wgt', `fallergy`='$fallergy', `mallergy`='$mallergy' WHERE `patientid`='$vara'");
$result = mysql_query($edit) or die("Verification Error: " . mysql_error());
You are calling mysql_query twice; the second time you pass the result, of the first call, into it as an argument. That is not how mysql_query works. The SQL should just be a string:
$edit = "UPDATE `patient` SET `date`='$date', `fname` ...";
$result = mysql_query($edit) or die("Verification Error: " . mysql_error());
We cannot see the rest of your code, so we do not know if there are more problems, but this should fix the problem in your question.
While the following query works with phpmyadmin, when I use mysqli->query(), a syntax error occurs
START TRANSACTION;
SELECT Value INTO #Increment FROM SystemConfiguration WHERE `Key` = 'POIncrement' FOR UPDATE;
UPDATE SystemConfiguration SET Value = Value + #Increment WHERE `Key` = 'POID';
COMMIT;
The syntax error message:
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 'SELECT Value INTO #Increment FROM SystemConfiguration WHERE `Key` = 'POIncrement' at line 2
Is it that mysqli prepares the query and adds something in?
$sql = <<<SQL
START TRANSACTION;
SELECT Value
INTO #Increment
FROM SystemConfiguration
WHERE `Key` = 'POIncrement' FOR UPDATE;
UPDATE SystemConfiguration
SET Value = Value + #Increment
WHERE `Key` = 'POID';
COMMIT;
SQL;
$res = mysqli_multi_query($connection, $sql);
I have tried for hours now to update a MySQL table with PHP.
I used the following code (and several others) but it gives an error message:
$id = $_GET['id'];
if(isset($_POST['descr'])){
$go = $_POST['descr'];
mysql_query("UPDATE Rooms SET Desc='$go' WHERE Room_ID='$id'")
or die(mysql_error());
}
mysql_close($conn);
with the error: "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 'Desc='This room is the primary test-room. It is?' WHERE Room_ID='11'' at line 1"
The form is called: "descr", the table "Rooms", the field that needs update is "Desc" and it should be where the corresponding ID is, based on a dynamic URL.
If I write echo = $go it outputs the correct data, so I suppose it's the php.
It DOES connect correctly to the database.
Desc is a special word in mysql
try it by escape
mysql_query("UPDATE Rooms SET `Desc`='$go' WHERE Room_ID='$id'")
Assuming that ID is a number:
$id = $_GET['id'];
if(isset($_POST['descr'])){
$go = $_POST['descr'];
mysql_query("UPDATE Rooms SET `Desc`='".$go."' WHERE Room_ID=".$id.")
or die(mysql_error());
}
mysql_close($conn);
Desc is reserved for ORDER BY! Enclose it with '`' symbols!
mysql_query("UPDATE `Rooms` SET `Desc` = '".$go."' WHERE `Room_ID` = ".$id.")
or die(mysql_error());