I keep getting this syntax error in my MySQL code within a PHP file. I'm simply trying to increment/add to the value already in the table with this time variable. If anyone could help me out I'd greatly appreciate it.
PHP:
$sql = "UPDATE Aircraft
SET MaintenanceFlightTime = (MaintenanceFlightTime + $MaintenanceDuration),
WHERE AircraftID = $AircraftID";
Error:
UPDATE Aircraft SET MaintenanceFlightTime = (MaintenanceFlightTime + 00:10:00), WHERE AircraftID = 8
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':10:00), WHERE AircraftID = 8' at line 2
You cannot just add a string like '01:01:01' to a time column but you can use ADDTIME()
$MaintenanceDuration = '00:10:00';
$sql = "UPDATE Aircraft
SET MaintenanceFlightTime = ADDTIME(MaintenanceFlightTime, '$MaintenanceDuration')
WHERE AircraftID = $AircraftID";
here's the generated query:
UPDATE namelist
SET 'submitterName' = 'Jim'
,'actorName' = 'dingle'
,'setYear' = '1103'
,'country' = 'tanata'
,'blink' = 'on'
,'crush' = 'on'
,'initialize' = 'on'
,'entered' = 'on'
,'stuck' = 'on'
,'catapult' = 'on'
,'ruck' = 'on'
WHERE id = 31
it generates this (less than helpful) 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 (query snippet) at line 1
for the life of me, i can't spot where the problem is. yes, column names match, yes
TIA for helping out.
WR!
You have used single quotes before and after columns in the query, replace those single quotes with backquotes.
So the query like
UPDATE namelist
SET `submitterName`='Jim',
`actorName`='dingle',
`setYear`='1103',
`country`='tanata',
`blink`='on',
`crush`='on',
`initialize`='on',
`entered`='on',
`stuck`='on',
`catapult`='on',
`ruck`='on'
WHERE id=31;
user ` instead of '
like this
UPDATE namelist SET `submitterName`='Jim',`actorName`='dingle',`setYear`='1103',`country`='tanata',`blink`='on',`crush`='on',`initialize`='on',`entered`='on',`stuck`='on',`catapult`='on',`ruck`='on' WHERE id=31
$request_id_col and $request_id are strings. However, the request_id_col type in the table is an integer.
$stmt = $db->prepare(' SELECT r.qty, d.name
FROM requested_devices r
JOIN devices d ON r.device_id = d.id
WHERE r.:request_id_col = :request_id
ORDER BY r.id');
$stmt->bindParam(':request_id_col', $request_id_col);
$stmt->bindParam(':request_id', $request_id);
$stmt->execute();
I'm receiving 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 ''sample_id' = '101' ORDER BY r.id' at line 4'
How do I make a query by correctly using bindParam's?
You can't bind table or column names. Only values.
This is query I am using to insert into the table.
I am getting the error like this
$sql = mysql_query("INSERT INTO userinfo(runnername,runnerdob,runnerage,runnergender,runneraddress,runnercity,runnerstate,runnerpincode,runneremail,runnerpassword,runnermobilenumber,e_name,e_relationship,e_address,e_mobilenumber,height,weight,bloodgroup,category,tshirtsize,accountcreationdate,lastlogin,timestamp,registereduser,ipaddress,status)
VALUES('$runnername','$dt',$runnerage,'$runnergender','$runneraddress','$runnercity','$runnerstate','$runnerpincode','$runneremail','$epassword','$runnermobilenumber','$e_name','$e_relationship','$e_address','$e_mobilenumber','$height','$weight','$bloodgroup','$category',$tshirtsize,'$accountdate','Y','$t','Y','$ip',1") or die(mysql_error());
This is generated output
INSERT INTO
userinfo(runnername,runnerdob,runnerage,runnergender,runneraddress,runnercity,runnerstate,runnerpincode,runneremail,runnerpassword,runnermobilenumber,e_name,e_relationship,e_address,e_mobilenumber,height,weight,bloodgroup,category,tshirtsize,accountcreationdate,lastlogin,timestamp,registereduser,ipaddress,status)
VALUES('VIDHYA PRAKASH R','1985-04-08',29,'M','12 DIVINE
RESIDENNCY','coimbatore','TAMILNADU','641035','vidhyaprakash85#gmail.com','FU4A31/GhcmRItAHb97lNtrjRZr+y1yG4arxawG/qEs=','9944524864','rajendran','father','12
DIVINE RESIDENNCY coimbatore TAMILNADU
641035','9894773083','6','6','A1+ve','M',42,'11-07-2014
12:11:02','Y','1405060862','Y','127.0.0.1',1)
but I am getting error as
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 '' at line 1
I am breaking my head for past two hours.
Any one please help me ?
The issue was at the end of the query, writing long insert queries on single line should be avoided and better to write in multiple lines which helps to find the issue almost immediately , or the best is to use prepared statement with PDO or mysqli.
Your query ends as 'Y','$ip',1") which was missing )
Here how the query should be
$sql = mysql_query(
"INSERT INTO userinfo
(
runnername,
runnerdob,
runnerage,
runnergender,
runneraddress,
runnercity,
runnerstate,
runnerpincode,
runneremail,
runnerpassword,
runnermobilenumber,
e_name,
e_relationship,
e_address,
e_mobilenumber,
height,
weight,
bloodgroup,
category,
tshirtsize,
accountcreationdate,
lastlogin,
timestamp,
registereduser,
ipaddress,
status
)
VALUES
(
'$runnername',
'$dt',
$runnerage,
'$runnergender',
'$runneraddress',
'$runnercity',
'$runnerstate',
'$runnerpincode',
'$runneremail',
'$epassword',
'$runnermobilenumber',
'$e_name',
'$e_relationship',
'$e_address',
'$e_mobilenumber',
'$height',
'$weight',
'$bloodgroup',
'$category',
$tshirtsize,
'$accountdate',
'Y',
'$t',
'Y',
'$ip',
1
)"
) or die(mysql_error());
Are you missing a close bracket at the end of your values statement?
Instead of
'$ip',1")
Shouldn't it be
'$ip',1)")
I'm trying to delete some data from 3 tables. Here is my SQL:
DELETE
FROM productdetail
JOIN (productdescription,productmineralcategories,productspeciescategories)
ON
(
productdetail.id = productspeciescategories.id_product
AND productdetail.id = productmineralcategories.id_product
AND productdetail.id = productdescription.id_product
)
WHERE productdetail.id='".$data['id'].
And here is the output error:
Error Number: 1064
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 'JOIN (productdescription, productmineralcategories,
productspeciescategories) ' at line 3
What does it mean and how can I fix it?
Your DELETE statement should be:
$query="DELETE
FROM productdetail
WHERE productdetail.id='".$data[$id] . "'";
OR
$query="DELETE
FROM productdetail
WHERE productdetail.id='$data[$id]'";
OR do not add single quote if field type is numeric.
$query="DELETE
FROM productdetail
WHERE productdetail.id=$data[$id]";
Have a look at DELETE JOIN syntax.