gpt4 book ai didi

php - 如何在 PHP 中同时创建表格、更改列并向其中插入数据?

转载 作者:行者123 更新时间:2023-11-28 00:56:20 24 4
gpt4 key购买 nike

<分区>

我想将数据从 HTML 发送到 PHP 并使用 POST 并首先使用表值创建表并使用列值更改添加列,最后想在我从 HTML 发送时将数据插入到具有数据值的列中,但无论我做什么,它都会出错。

这是我的 HTML 代码。

<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>

这是我的 PHP 代码,

<?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";
}

?>

这是我遇到的错误:

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com