[英]Simple INSERT doesnt work?
This simple code won't work and I really dont't know why 这个简单的代码行不通,我真的不知道为什么
Any help will be appreciated 任何帮助将不胜感激
<body>
<?php
if (isset($_POST["submit"])) {
$sql = "INSERT INTO am (schulwoche,kalenderwoche,lehrstoff,anmerkungen,lehrer) VALUES ('".$_GET["sw"]."','".$_GET["kw"]."','".$_GET["ls"]."','".$_GET["an"]."','".$_GET["le"]."')";
$conn->query($sql1);
}
?>
<div class="anzeige">
<form action="insert.php" method="post">
<b>Schulwoche: </b><input type="text" name="sw"><br>
<b>Kalenderwoche: </b><input type="text" name="kw"><br>
<b>Lehrstoff: </b><input type="text" name="ls"><br>
<b>Anmkerkungen: </b><input type="text" name="an"><br>
<b>Lehrer: </b><input type="text" name="le"><br>
<input type="submit" value="Eintragen">
</form>
What is the error you receive? 您收到什么错误? My bet is that one of the get variables are missing at run time and you are trying to insert a null into a required field. 我敢打赌,运行时缺少get变量之一,而您试图在必填字段中插入null。
Its also possible that there are other fields in your am table that you are not populating using your php/sql insert syntax. 还有可能是您的am表中还有其他字段未使用php / sql插入语法填充。
Try this 尝试这个
$sql = "INSERT INTO am (schulwoche,kalenderwoche,lehrstoff,anmerkungen,lehrer) VALUES ('".$_GET["sw"]."','".$_GET["kw"]."','".$_GET["ls"]."','".$_GET["an"]."','".$_GET["le"]."')";
echo $sql;
Then copy the SQL and try run it directly on your database via the terminal or something. 然后复制SQL并尝试通过终端或其他方式直接在数据库上运行它。 You will quickly see what is wrong. 您将很快发现问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.