0

I need to create a table with the class name given by the user in my Android application. I tried to do it with following code but I get errors.

What's going wrong?

$con = mysqli_connect("mysql.hostinger.in","u975450189_****","********","u975450189_****");

$classname = $_POST["classname"];
$classid = $_POST["classid"];

$statement = mysqli_prepare($con, "CREATE TABLE ?(id int(20) AUTO_INCREMENT PRIMARY KEY,? VARCHAR(20) NOT NULL);");
mysqli_stmt_bind_param($statement, "ss", $classname, $classid);
mysqli_stmt_execute($statement);

$response = array();
$response["success"] = true;

print_r(json_encode($response));

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/u975450189/public_html/ClassCreate.php on line 10

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/u975450189/public_html/ClassCreate.php on line 11 {"success":true}

Community
  • 1
  • 1
Manoj
  • 13
  • 6
  • Duplicate question, you can find your awnser here: http://stackoverflow.com/questions/2228430/mysqli-throws-warning-mysqli-stmt-bind-param-expects-parameter-1-to-be-mysql – RCode Jul 03 '16 at 09:55
  • i didnot understand that,i think my case is different whenever itry to create table with post info i am gettin error but when i want t insert any values it is working fine – Manoj Jul 03 '16 at 09:57
  • @manoj: for adding code sample: just edit your post. –  Jul 03 '16 at 10:06
  • can someone please tell whats wrong – Manoj Jul 03 '16 at 12:38
  • 1
    Does this answer your question? [Can I parameterize the table name in a prepared statement?](https://stackoverflow.com/questions/11312737/can-i-parameterize-the-table-name-in-a-prepared-statement) Also see [mysqli->prepare issue with creating tables](https://stackoverflow.com/questions/28266169/mysqli-prepare-issue-with-creating-tables). – showdev Jan 28 '20 at 10:50

0 Answers0