Hello everyone, I am trying to select the a value from the database such as

 $stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = (the most recent value entered ');

i tried :

$stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = "26" '); 

and it was successful. However whenever I try something like :

$stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = :acc_id');


$stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = $acc_id ');

i get the following error :

core.js:1350 ERROR SyntaxError: Unexpected token S in JSON at position 0
at JSON.parse (<anonymous>)

What am I doing wrong ? How can I fix it ??
Thank you in advance!

SELECT acc_id FROM account_info ORDER BY acc_id DESC LIMIT 1 worked but the value showed up localhost:10080/ionic/patients.php

Makes sense, because you define a variable that you never set via execute() or bindParam().
And do not look at any JS error when debugging PHP. Set your PDO to throw exceptions.

I want to later insert that value in another table as Forgein key ?
is there a better way to get the value? please if so i’d be grateful to know it

What you say makes no sense. There is :acc_id, which you never provide any value for the statement. There is $acc_id, which will never be evaluated within single quotes. There’s an error in core.js, that has nothing to do with PHP or SQL. Until you do not get any value, you have nothing for a later insert, which is not part of your original post. You did not say anything on the debugging tip.

I fixed that is another topic do you mind please checking it out ? Insert Selected data in database Thank you!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.