<?php mysql_connect ("localhost", "username", "password") or die(mysql_error()); mysql_select_db ("DB_name") or die(mysql_error()); $searchTerm = $_POST['searchTerm']; $createTable = "CREATE TABLE " . $searchTerm . "(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT)"; $mysqlString = "INSERT INTO " . $searchTerm . " (name, age) VALUES('" . $someVar . "', '" . $anotherVar . "' )"; mysql_query($mysqlString) or mysql_query($createTable) or die(mysql_error());
But whenever I use a search term that is not allready in the database i get the following error.
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 'test( id INT NOT NULL AUTO_I' at line 1
Even more wierd to me is that whatever the search term I use is displayed as bold in my error message. Even when I add some random string onto the search term variable, only the part that was actually part of the HTML form is bold. My current theory is that for some reason the HTML forms send some wierd type of a string that doesnt make MYSQL happy but I have no idea. I'm so confused. Any help would be greatly appreciated. Thanks in advance!