user3175451
user3175451

Reputation: 163

PHP will not create mysql table, but can be entered manually.

I am trying to create a table for an item's bid history upon the items insertion to the items table.

I am getting this error:

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 ''19' ( user_pk INT(20)unsigned, maxbid DECIMAL(16,8)un' at line 1

create table item'19' ( user_pk INT(20)unsigned, maxbid DECIMAL(16,8)unsigned, bid DECIMAL(16,8)unsigned, ip VARCHAR(80), winning BOOLEAN NULL )

Filename: /home/content/61/11420661/html/btcbidder.com/controllers/user.php

Line Number: 253

The code for that line is:

                        $this->db->query("CREATE TABLE item'$currentId' (
                                            user_pk INT(20)unsigned,
                                            maxbid DECIMAL(16,8)unsigned,
                                            bid DECIMAL(16,8)unsigned,
                                            ip VARCHAR(80),
                                            winning BOOLEAN NULL
                                            )");

If I create the table manually by entering something like item23 for the table name into SQL query browser, the table is created successfully.

What am I doing wrong?

Upvotes: 1

Views: 61

Answers (1)

radar
radar

Reputation: 13425

you can try this, using . to concatenate query string and variable.

$this->db->query("CREATE TABLE item". $currentId ." (
                                        user_pk INT(20)unsigned,
                                        maxbid DECIMAL(16,8)unsigned,
                                        bid DECIMAL(16,8)unsigned,
                                        ip VARCHAR(80),
                                        winning BOOLEAN NULL
                                        )");

Upvotes: 1

Related Questions