Zera42
Zera42

Reputation: 2692

PDO insert query failing

PHP:

    if(strcasecmp($refId, 'guest') == 0)
    {
        if(strcasecmp( $amount, '24.95' ) == 0)
        {
                $credits = 20;
                $plan = 'cool';     
        }
        if(strcasecmp( $amount, '45.95' ) == 0)
        {
            $credits = 40;
            $plan = 'awesome';
        }
        if(strcasecmp( $amount, '69.95' ) == 0)
        {
            $credits = 60;
            $plan = 'Supreme';
        }

            $keyy = generate_key_string();
            $query = $pdo->prepare("INSERT INTO keys (keys_key, keys_plan, keys_credit) VALUES (?, ?, ?)"); 
            $query->bindValue(1, $keyy);
            $query->bindValue(2, $plan);
            $query->bindValue(3, $credits);
            if(!$query->execute())
            {
                echo 'failed' . '<br/>';
                echo $plan . '<br/>';
                echo $keyy . '<br/>';
                echo $credits;

            }           
    }

SQL table:

CREATE TABLE `keys` (
  `keys_key` varchar(29) NOT NULL,
  `keys_credits` int(11) NOT NULL,
  `keys_plan` varchar(255) NOT NULL,
  PRIMARY KEY  (`keys_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

I know the values are there because that's my output

failed
cool
CDGSI-DUEXP-M9BUZ-4VMQA-YSLIU
20

the query doesn't seem to be working for just this insert, I have different insert functions on other pages and they work fine. Thanks

Upvotes: 0

Views: 87

Answers (1)

echo_Me
echo_Me

Reputation: 37233

keys is reserved keyword you should escape your columns and tables if you use reserved keywords by backticks

like that

    INSERT INTO `keys`

Upvotes: 4

Related Questions