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.
Related
Code runs in phpmyadmin but not running in my php code and says the code has syntax problem.
What is the problem ?
INSERT INTO `users`(`username`, `email`, `password`) VALUES ( 'test' , 'test#email.com' , '13456');
UPDATE `users` SET `email`='test2#email.com'
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 'UPDATE `users` SET `email`='test2#email.com'' at line 1 (SQL: INSERT INTO `users`(`username`, `email`, `password`) VALUES ( 'test' , 'test#email.com' , '13456'); UPDATE `users` SET `email`='test2#email.com')
You can't run two queries from PHP in one call, unless you use mysqli_multi_query(). Split them into two separate calls.
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!
This works fine:
...
$sql = "INSERT INTO person (`name`, `age`)
VALUES ('John', 34);";
$stmt = $conn->prepare($sql);
...
But this gives an error:
...
$sql = "BEGIN
INSERT INTO person (`name`, `age`)
VALUES ('John', 34);
END;";
$stmt = $conn->prepare($sql);
...
The error is:
SyntaxError: unterminated string literal
And more specifically:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'INSERT INTO person (`name`, `age`)
I know that the BEGIN ... END is unnecessary in this contrived example, but why does it not work?
Thanks very much for any help.
In PDO, like in any other API, you run separate queries using separate API calls:
Given the END keyword makes no sense and assuming you meant COMMIT,
$conn->query("BEGIN");
$conn->query("INSERT INTO person (`name`, `age`) VALUES ('John', 34)");
$conn->query("COMMIT");
However, you have to keep in mind that
there is no point in running a transaction for a single query
there is no point in using a prepared statement if you bind no data to it
When I proceed to run the following query:
$sql3 = mysqli_query($con, 'INSERT INTO berichten (from, naar, file) VALUES ('.$id.', '.$to.', "'.$url.'")') or die(mysqli_error($con));
I'll received 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 'from, naar, file) VALUES (2, 2, "b9173a1b9ade8767280009f9638bd987.caf")' at line 1
id = an id number,
to = an id number and
url = the filename (e.g. sound.caf)
Why do I get this error and what to do to fix it?
Thanks!
from is a special SQL keyword. You have to escape it by putting it into backticks:
$sql3 = mysqli_query($con, 'INSERT INTO berichten (`from`, naar, file) VALUES ('.$id.', '.$to.', "'.$url.'")') or die(mysqli_error($con));
Besides that you might need to quote ID and file as you did for $url.
Btw. You should really consider to use prepared statements in order to prevent SQL injections.
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.