我正在尝试通过 html 向我的 mysql 表中添加新元素 到目前为止我已经得到了这个
<form action="MyCurrentFile.php" method="post" >
Artist Name
<input type="text" name="addingnewelement" <br/>
<input type = "submit" name = "Submit" />
</form>
还有这个
<?php
if (isset($_POST['submit'])) {
$addingelement=$_POST['addingnewelement'];
$mysqli->select_db("names", $names);
echo("this code is running");
$sql='INSERT INTO names (nameValue) VALUES ('.$addingelement.')';
$mysqli->query($sql, $mysqli);
$mysqli->close($mysqli);
}
?>
我的语法有什么错误吗?代码没有给我任何错误,所发生的只是我按下我的按钮以更新我的输入但没有任何反应。
最佳答案
你需要把hte artist name 作为label 并关闭input,提交按钮的名字和你其他页面的名字一样。
<form action="MyCurrentFile.php" method="post" >
<label for="artistName">Artist Name</label>
<input type="text" id="artistName" name="addingnewelement" value=""/>
<input type="submit" name="submit" value="submit"/>
</form>
您的 sql 查询也是错误的 - 它应该是:
$sql="INSERT INTO names (nameValue) VALUES ('".$addingelement."')";
关于php - 通过html向mysql表中添加新元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36936637/