I want to send data from HTML
to PHP
and with POST
and create table first with table value and alter add column with column value, and finally want to insert data into the column with data values when I send from HTML
,
but no matter I do it keeps having error.
Here is my HTML Code.
<form method="post" action="table2.php">
Table<input type="text" name="table"><br>
Column<input type="text" name="column"><br>
Data<input type="text" name="data"><br>
<input type="submit" value="submit">
</form>
and here is my PHP code,
<?php
include_once("login2.php");
$table = $_POST['table'];
$column = $_POST['column'];
$data = $_POST['data'];
$createTable = "create table ".$table."(
id int not null auto_increment,
nickname varchar(50),
primary key(id)
)";
/* Create Table */
if(mysqli_query($conn, $createTable)){
echo "<br><br>";
echo "table created successfully";
$alterColumn = "alter table ".$table." add ".$column. "varchar(100)";
}else{
echo "<br><br>";
echo "Failed to create databases";
}
/* Alter add Column into the Table */
if(mysqli_query($conn, $alterColumn)){
echo "<br><br>";
echo "column created successfully";
$insertValue = "insert into ".$table."(".$column.")values(".$data.");";
}else{
echo "<br><br>";
echo "Failed to alter column";
}
/* Insert data into the Column above */
if(mysqli_query($conn, $insertValue)){
echo "<br><br>";
echo "Every process successfully done.";
}else{
echo "<br><br>";
echo "Failed to insert data";
}
?>
Here are the errors that I have:
Warning: mysqli_query(): Empty query in C:\xampp\htdocs\practice\table2.php on line 30
Notice: Undefined variable: insertValue in C:\xampp\htdocs\practice\table2.php on line 41
Warning: mysqli_query(): Empty query in C:\xampp\htdocs\practice\table2.php on line 41