please, why doesn't this sql update query work? - php

//my update query
$query = "UPDATE articles SET
title='$title',
author='$author',
body='$body'
WHERE id = {$uid}";
Error
ERROR: 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 '' at line 5
Now, I using mysqli extension with PHP.

Related

check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIMIT 1' at line 1

this is the error i get... ou have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIMIT 1' at line 1
my code looks like this:
$sql = "SELECT * FROM posts WHERE id=$pid LIMIT 1";
I mean where can i find the manual?
and what do i wrong?

I have a problem in update mysql information

I have a little problem. I tried to update information in HTML form, and when I write "I'm example" I receive this error
A little help?
Error updating record: 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 'da', gender='2', locationUser='Here', userBirthday='26/05/1993' WHERE PlayerID='' at line 1
Code:
$sql = "UPDATE users SET descriptionProfile='$prezentare', gender='$gender', locationUser='$localisation', userBirthday='$anniversaire' WHERE PlayerID='$pr'";
A single or double quote break your query. Use this query
$sql = "UPDATE users SET descriptionProfile='".$prezentare."', gender='".$gender."', locationUser='".$localisation."', userBirthday='".$anniversaire."' WHERE PlayerID='".$pr."'";
Extend #Ariful answer,
For lower version of Mysql, you have to use below Query
$sql = "UPDATE `users` SET `descriptionProfile`='".$prezentare."', `gender`='".$gender."', `locationUser`='".$localisation."', `userBirthday`='".$anniversaire."' WHERE `PlayerID` ='".$pr."'";
Hope this will help.

check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id=' \r\n

I am new to php and cannot get this! I'm attempting to edit data on an edit page which will be stored through an update page onto mySQL.
<?php
include("secure/connect.php");
$newtitle = mysqli_real_escape_string($conn, ($_POST['title']));
$newinfo = mysqli_real_escape_string($conn,($_POST['info']));
$newprice = mysqli_real_escape_string($conn,($_POST['price']));
$newmenu_img = mysqli_real_escape_string($conn,($_POST['menu_img']));
$id = mysqli_real_escape_string($conn, ($_POST['rowid']));
//setup a SQL query
$query= "UPDATE cocktails SET title='$newtitle', info='$newinfo', price='$newprice', menu_img='$newmenu_img', WHERE id='$id'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
mysqli_close($conn);
?>
I keep getting the error:
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 'WHERE id='
\r\nNotice: Undefined variable: iddata in /var/www/vh' at line 1
If your parameters are OK, removing comma(,) in this line
UPDATE cocktails SET title='$newtitle', info='$newinfo', price='$newprice', menu_img='$newmenu_img', WHERE id='$id'
before WHERE will do the job. Note that MariaDB will start code in error message from exactly the part that gives error - in your case it tries to parse WHERE part as continuation of list of parameters.
Your code is also vulnerable to SQL code injection, so check out this answer before sending your code into production server.

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use

I keep getting the error:-
"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 'Password='evertonblues' Forename='Josh' Surname='Edmondson'
Date of Birth='199' at line 1"
error when running my update query.
$result = mysqli_query($con, "UPDATE Users SET Username='".$newUsername."' Password='".$newPassword."' Forename='".$newForename."' Surname='".$newSurname."' `Date of Birth`='".$newDateofBirth."' Address='".$newAddress."' `Post Code`='".$newPostcode."' Email='".$newEmail."' `Phone Number`='".$newPhonenumber."' WHERE `User ID`='".$newUserid."';");
You forgot a bunch of commas:
..snip... SET Username='".$newUsername."' Password='".$newPassw
^-- and many others
Use query as below:
"UPDATE Users SET `Username`='".$newUsername."', `Password`='".$newPassword."', `Forename`='".$newForename."', `Surname`='".$newSurname."', `Date of Birth`='".$newDateofBirth."', `Address`='".$newAddress."', `Post Code`='".$newPostcode."', `Email`='".$newEmail."', `Phone Number`='".$newPhonenumber."' WHERE `User ID`='".$newUserid."';");
Also space in Date of Birth

MySQLi Inconsistent Syntax Error

I am trying to enter data into my MySQL database using the following query
UPDATE `Customer Table` SET `ID`=$ID, `First name`='$FirstName',`Last name`='$LastName',`Home phone number`=$HomePhoneNumber,`Mobile phone number`=$MobilePhoneNumber,`House number`=$HouseNumber,`House name`='$HouseName',`Street name`='$StreetName',`Town name`='$TownName',`Post code`='$PostCode' ,`Notes`='$Notes' WHERE ID=$ID
This is working fine when I'm calling it from one PHP file but not working when I'm calling it from an API PHP file.
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 '`House number`=0,`House name`='43',`Street name`='Westbury',`Town name`='We' at line 1
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 '`House number`=0,`House name`='3',`Street name`='Close',`Town name`='Thorn' at line 1
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 '`House number`=0,`House name`='flat',`Street name`='2 road',`Town ' at line 1
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 '`House number`=0,`House name`='39',`Street name`='valley',`Town name`='',`' at line 1
Can anyone see where the error is as I'm struggling to find it. All of the data types are correct from what I can see.
Thanks in advance, Luke.
Try this. It seems that your variable $MobilePhoneNumber contains string part within it something like +
"UPDATE `Customer Table` SET `ID` = '$ID', `First name` = '$FirstName',
`Last name`= '$LastName',`Home phone number`= '$HomePhoneNumber',
`Mobile phone number` = '$MobilePhoneNumber',`House number` = '$HouseNumber',
`House name`='$HouseName',`Street name`='$StreetName',`Town name`='$TownName',
`Post code`='$PostCode',`Notes`='$Notes' WHERE ID=$ID"
Gordon Linoff suggestions was best, $MobilePhoneNumber was not being read from my XML file.+ "<MobilePhoneNumber>" + MobileNumber + "</MobileNumber> was being written instead of + "<MobilePhoneNumber>" + MobileNumber + "</MobilePhoneNumber>

Categories