Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


sql insert where statment need help 0.o??? filter_list
Author
Message
sql insert where statment need help 0.o??? #1
Trying to use the following statement  in php using pdo and sqlite
keep getting errors
The separate vars can be echo'd out, so there is no problem with the inputs.
Have no problem doing a simple insert (for new row any column) and select  whatever from table column where row = 1
Looks so simple i just can't quite get i right
Code:
INSERT INTO table  ('stringstore')
VALUES ('string')
WHERE ('id') = ('100')

errorcode :
near "WHERE": syntax error:
php code
Code:
$id = "100";

if(!empty($astring))
{
   $string = $astring;
   $db = new PDO('sqlite:sqlite.db');
   $result = $db->prepare("INSERT INTO table ('stringstore') VALUES ('$string') WHERE id = ('$id')");
#debuging
if (!$result)
{
   echo "\nPDO::errorInfo():\n";
   print_r($db->errorInfo());
}
   $result->execute();
   
}

error:
Call to a member function execute() on boolean

cheers

Biggrin

Num5kull
(This post was last modified: 06-02-2017, 12:20 AM by Num5kull.)
[Video: https://www.youtube-nocookie.com/embed/bOkD-HSOmyI]
[bt][1B1sXX2sHhvUrf9Ga9MKcH5e9T4xgN13tB]

Reply

RE: sql insert where statment need help 0.o??? #2
With your SQL INSERT INTO Statement, you've enclosed the id column In single quotes and you haven't ended your SQL query In a semicolon, hence the syntax error  near "WHERE".

The value of '100' Is fine (single quotes), but given the id column Is only one word (not separated) you can either enclose It In "Back Ticks", or leave It as Is, but NOT single quotes.

Example:
Column In Back Ticks
Code:
 WHERE (`id`) = ('100') ;

No Back Ticks
Code:
WHERE (id) = ('100') ;

Either of the two will work. Don't forget to use the semicolon at the end of the statement.
[Image: AD83g1A.png]

[+] 2 users Like mothered's post
Reply







Users browsing this thread: 2 Guest(s)