can't wrap my head around this SQL syntax error - php

Hei.. I can't wrap my head around it what the problem here might be.
if (!$vote['vid'] and $rq['submitpoll'] and $rq['answer'] and $rq['pid']){
$my->my_query ("INSERT INTO ".TBL_PF."votes (pid, aid, ip) VALUES (".$rq['pid'].", ".$rq['answer'].", ".ip2long($_SERVER['REMOTE_ADDR']).")");
$vote['vid'] = true;
the error I get is
INSERT INTO qwerty_votes (pid, aid, ip) VALUES (1, 10, )
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
maybe someone can enlighten me?
Thank you so much!

Related

how to rectify this "SQL syntax" in php&mysql

i'm trying to create a tagging sys demo here. And i'm stumped why i get this 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 '#ok )' at line 1
here is my code:
$insert=mysqli_query($conn, 'insert into `hashtag` (posts) values ('.$data1.')') or die(mysqli_error($conn));
any help would be appreciated.
In mysqli query you don't have to put $conn .
Just remove it and in query put like this '".$data1."' And check.

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>

You have an error in your SQL syntax with table and connection

Im getting this error, I can't figure out why thought:
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 'Case (clientforename, clientsurname) VALUES ('ghghgj', 'ffhhf')' at line 1
this is the php code:
mysql_query("INSERT INTO Case (clientforename, clientsurname)
VALUES ('$clientforename', '$clientsurname')")
or die(mysql_error());
Case is a reserved keyword. You must wrap it in ticks:
mysql_query("INSERT INTO `Case` (clientforename, clientsurname)
VALUES ('$clientforename', '$clientsurname')")
or die(mysql_error());

ERROR When trying to insert into MySQL table with PHP

I don't know what's wrong with my syntax, but I'm missing something:
$createrequest = mysql_query("INSERT INTO products_updates_queue (id, kid,
product_version_id, key, ip) VALUES ('$request_id', '$uid', '$version_id',
'$request_key', '$request_ip')");
I receive this 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 'key, ip) VALUES ('j4ctveyd0x62', '1', 'z451ah3', 'hqbyu7bhg8za', '64.134.163.2' at line 2"
Can anyone see what I am missing?
I think key is a reserved word, and you should avoid using it as a column name. Try using backticks around it:
$createrequest = mysql_query("INSERT INTO products_updates_queue (id, uid, product_version_id, `key`, ip) VALUES ('$request_id', '$uid', '$version_id', '$request_key', '$request_ip')");
key is a reserved word in MySQL. Avoid it, or wrap it in backticks.
Edit: And I hope you escaped the variables you're putting into that query.

CodeIgniter not correctly performing a sql query

In Ci I'm getting the following error:
A Database Error Occurred
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 '', '1f37540fc54292b018a9e993da38cb5647dc5587', NOW(), '0')' at line 1
INSERT INTO users (userpid, Email, Password, dateTimeRegistered, isLeader) VALUES ('147344f0e33367f9e6', erf', '1f37540fc54292b018a9e993da38cb5647dc5587', NOW(), '0')
Filename: C:\Workspace\htdocs\Misc-2\DruvlaCi-1\system\database\DB_driver.php
Line Number: 330
But everything seems to be right in the SQL query. Below is my query, any thoughts?
$query = $this->db->query("INSERT IGNORE INTO users (userpid, Email, Password, dateTimeRegistered, isLeader) VALUES ('{$idgen}', {$postedEmail}', '{$hashedPass}', NOW(), '0')");
You're forgetting the opening single quote for the email column
Try this instead
$query = $this->db->query("INSERT IGNORE INTO users (userpid, Email, Password, dateTimeRegistered, isLeader) VALUES ('{$idgen}', '{$postedEmail}', '{$hashedPass}', NOW(), '0')");
Uhm, and please, use this syntax for inserting instead:
http://codeigniter.com/user_guide/database/active_record.html#insert
works so much safer.

Categories