Im creating a forum where user can create a poll by giving the question and options. Then I send these to a database using Ajax and PHP and create a table with the name PollTable0. And as new ones get added the number increases s.a. "PollTable1", "PollTable2" etc. I get these numbers by counting the number of tables in the database. My code looks like this:
<?php
if (isset($_POST['NewPoll'])) {
$PollArray = $_POST['NewPoll'];
}
$con = mysqli_connect("localhost", "root", "123", "polldatabase") or die("DIE");
$getnumber = "SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA='polldatabase'";
$number = mysqli_query($con, $getnumber);
$sql = "CREATE TABLE PollTable" . $number . " (" . $PollArray[0] . "VarChar(255))";
mysqli_query($con, $sql);
for ($i = 1; $i < count($PollArray); $i++) {
$target = "ALTER TABLE PollTable" . $number . " ADD " . $PollArray[i] . " VARCHAR(255)";
mysqli_query($con, $target);
}
echo "Thank you for submitting your poll";
mysqli_close($con);
?>
Now the problem is $number is an I believe sql result object. Therefore when adding up the string with $number it gives the error:
Object of class mysqli_result could not be converted to string
If I am right, is there a way of converting result objects to strings. I have tried strval() and some other methods, which didnt work. If I am wrong, what do you think is the reason I am getting this error? Thanks in advance.