Notdildobike
Notdildobike

Reputation: 1

How do i fix this sql error? i dont know the cause of it

Error:

<br />
<b>Warning</b>:  PDO::prepare() expects parameter 1 to be string, object given in <b>/home/censored/public_html/no/level/level.php</b> on line <b>13</b><br />
<br />
<b>Fatal error</b>:  Call to a member function execute() on boolean in <b>/home/censored/public_html/no/level/level.php</b> on line <b>14</b><br />

code:

id = message.author.id;
    req.post(
        "http://(censored)/level/level.php",
        {
            form: {
                id: id
            }
        },
        function callback(err, httpResponse, body) {
    
    // the rest of the code is 100% not included in this error

php code:

$id = $_POST['id']

$queries = "INSERT INTO `discord` (`id`, `level`, `xp`, `xpreq`) VALUES (:name, `0`, `0`, `1`)";
$queries = $db->prepare($query);
$queries->execute([':name' => $id]);

i was making my discord bot using discord.js but i encounterred this error yesterday and i still cant fix it. i tried

turning the id into a string changing the sql code changing the php code turning the id into a string in the bot etc

still not fixed

Upvotes: 0

Views: 31

Answers (1)

vaso123
vaso123

Reputation: 12391

The problem is that you use wrong variable.

$queries = "INSERT INTO `discord` (`id`, `level`, `xp`, `xpreq`) VALUES (:name, `0`, `0`, `1`)";
$queries = $db->prepare($query);
                        ^^^^^^
$queries->execute([':name' => $id]);

You'v created a $queries variable for your query, but try to preapre the $query.

I bet, that you made a $query before, and you passed that to the preapre.

Upvotes: 1

Related Questions