This probably is not the most effective way to write this but i just started doing this a couple days ago. I am trying to create a table depending on user input from a form. The thing is with this code below im not sure how to add more than one variable as you can see in the examplebelow where $andanothervar is. I can create a table with $tableName and a table row with $row0, but once i add more than that the script runs without error but doesnt create a table.
$query = "CREATE TABLE $tableName
(
$row0 $anothervar $andanothervar
)";
I have tried using this below, but maybe i missed something in the book im reading.
$query = "CREATE TABLE $tableName
(
$row0 . ' ' . $type0 . ' ' . $attrib . ' ' . $null
)";
<?
$tableName = $_POST['tableName'];
$key = $_POST['key'];
$row0 = $_POST['row0'];
$type0 = $_POST['type0'];
$attrib0 = $_POST['attrib0'];
$null0 = $_POST['null0'];
$row1 = $_POST['row1'];
$type1 = $_POST['type1'];
$attrib1 = $_POST['attrib1'];
$null1 = $_POST['null1'];
$row2 = $_POST['row2'];
$type2 = $_POST['type2'];
$attrib2 = $_POST['attrib2'];
$null2 = $_POST['null2'];
$row3 = $_POST['row3'];
$type3 = $_POST['type3'];
$attrib3 = $_POST['attrib3'];
$null3 = $_POST['null3'];
$row4 = $_POST['row4'];
$type4 = $_POST['type4'];
$attrib4 = $_POST['attrib4'];
$null4 = $_POST['null4'];
$row5 = $_POST['row5'];
$type5 = $_POST['type5'];
$attrib5 = $_POST['attrib5'];
$null5 = $_POST['null5'];
$row6 = $_POST['row6'];
$type6 = $_POST['type6'];
$attrib6 = $_POST['attrib6'];
$null6 = $_POST['null6'];
$row7 = $_POST['row7'];
$type7 = $_POST['type7'];
$attrib7 = $_POST['attrib7'];
$null7 = $_POST['null7'];
@ $db = new mysqli('host', 'username', 'password', 'database');
if (mysqli_connect_errno()) {
echo "ERROR: Could not connect to the database.";
exit;
}
$query = "CREATE TABLE $tableName
(
$row0
)";
$result = $db->query($query);
$db->close();
?>
Thank your for any help.