97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says

I’ve worked with PHP and MySQL before but now when I’m trying learn PDO I hit the wall for some odd reason.

So if I try to create new table with this piece of code:

$sth = $dbh->prepare("CREATE TABLE `?` (`id` INT AUTO_INCREMENT PRIMARY KEY, `rating` FLOAT(5,2), `ip` VARCHAR(16))");
$sth->execute(array($this->table));

It will create table called ‘new_rating’, with those single quotes in it. But if I try to echo $this->table it will give me just new_rating, without any extra quotes like it should. So why it adds single quotes to table name? I’m surely missing something here, but what?

Btw, I’m willing to give one Spotify invite to person who can help me to solve this little problem! ;) (Of course only then if you can use Spotify in your country: https://www.spotify.com/fi/help/faq/availability/#country-availability)

1029 posts
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
  • Exclusive Author
  • Microlancer Beta Tester
  • United States
fillerspace says

Remove the backticks around the ? mark. CREATE TABLE `?` should be CREATE TABLE ?

97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says

I’ve tried that but then it gives me error:

Array
(
    [0] => 42000
    [1] => 1064
    [2] => 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 ''new_rating' (`id` INT AUTO_INCREMENT PRIMARY KEY, `rating` FLOAT(5,2), `ip` VAR' at line 1
)
1029 posts
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
  • Exclusive Author
  • Microlancer Beta Tester
  • United States
fillerspace says

According to the comments in the php official docs, table name substitution is not allowed. Using the question mark will add quotes, so you will have to use php string substition before passing it to statement prepare.

Http://www.php.net/manual/en/pod.prepare.php

97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says

I decided to go a bit different route because this issue but thanks anyway.

If you want that Spotify invite just give me you email address and I will sent it to you.

1029 posts
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
  • Exclusive Author
  • Microlancer Beta Tester
  • United States
fillerspace says

Sorry I couldn’t be more helpful

97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says

I already hoped that I would solved this but not quite yet. So I finally managed to got script working without any issues but now when I’m trying to implement it to Wordpress theme there is one little problem; It doesn’t work when Javascript is enabled! It catches all data and tries to sent it but it can’t insert it anywhere because it somehow loses database connection in middle of updating.

But when JS is disabled it works like a dream. Any ideas?

And sources of course:

PHP : http://pastebin.com/ZQMpmvFx

JS: http://pastebin.com/EEGYRmAF

97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says

Does anybody have any clue about this or will I settle for SQLite because at least it works either JS is enabled or not.

by
by
by
by
by
by