Trying to insert IP address but get an error - php

I'm trying to insert IP addresses into LastIP(An unsigned integer)
INSERT INTO user_entry (UPC, StateID, StoreID,CityID,Price,Count,LastIP) VALUES (885909301378,1,1,1,170,0,INET_ATON(127.0.0.1))
Error:
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 '.0.1))' at line 1

You need to add quotes:
INSERT INTO user_entry
(UPC, StateID, StoreID,CityID,Price,Count,LastIP) VALUES
(885909301378,1,1,1,170,0,INET_ATON("127.0.0.1"))
Source: Manual

Related

Why am I having a 1064 error in my SQL syntax?

Database error 1064 while doing query 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 '(subject,message,textmessage,entered, status) values("subject test"," html test"' at line 1
$result= Sql_query("insert into {$tables['messsage']}
(subject,message,textmessage,entered, status) values(\"subject
test\",\" html test\",\"text message test\",now(),\"draft\")");
The 1064 error can have multiple causes.
First of all: "sql_query" is pointing on your own function? If not you must change it with "mysql_query".
Anyway, you can check if all fields have the right type settings: varchar, text, datetime, timestamp, int...
Assuming that $tables['messsage'] is correct, you can try to change your code adding the char ` to table name:
$result = Sql_query("INSERT INTO `{$tables['messsage']}` (subject,message,textmessage,entered,status) VALUES (\"subject
test\",\"html test\",\"text message test\",now(),\"draft\")");
Hope it helps.

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>

SQLSTATE[42000] Error

Cant figure out where this query is going wrong...
getting this error:
{"databaseException":"SQLSTATE[42000]: Syntax error or access violation: 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 'desc) \n VALUES (1, array)' at line 1"
from this query
$statement = $db->prepare(
"INSERT INTO `descriptions` (vrm, desc) VALUES (:vrm, :description)"
);
if ($statement->execute(array(
':vrm' => '1',
':description' => $_POST['desc'])));
Thanks!
You should add backticks to the desc column name. It's a reserved word (ORDER BY vrm DESC).

UUID_SHORT regenerate if duplicate

I have this query:
$query = "INSERT INTO users (users_uuid, type_id) VALUES (UUID_SHORT(), :type_id)";
My question is if in case the UUID_SHORT() generated already exists, is there any way to tell MySQL to generate another UUID_SHORT() within that query? What I have in my mind now is to trap the return error response then execute again the query, which I find inefficient.
Based #eicto comment, I read ON DUPLICATE KEY UPDATE then tried to reconstruct my query, I achieve a new query:
$query = "INSERT INTO users (users_uuid, type_id) VALUES (UUID_SHORT(), :type_id) ON DUPLICATE KEY UPDATE (users_uuid) = VALUES(UUID_SHORT())";
However I received an error in my log that states:
"SQLSTATE[42000]: Syntax error or access violation: 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 '(users_uuid) = VALUES(UUID_SHORT())' at line 1"
What does this mean?

Categories