gpt4 book ai didi

php - 向MySQL数据库中插入数据(无数据)

转载 作者:太空宇宙 更新时间:2023-11-03 12:34:34 25 4
gpt4 key购买 nike

我想使用 php 将值保存在数据库中,我没有收到任何错误,但是数据库是空的,因此没有保存数据。

我放了 if 语句来检查之前是否保存了值

请检查我的代码

请帮帮我

<?php
$submit = $_POST['submit'];
$sid = strip_tags($_POST['sid']);
$Desc = strip_tags($_POST['Desc']);
if ($submit) {
// open data base
$connet = mysql_connect("localhost", "root", "hahaha1");
mysql_select_db("senior");
$sensorcheck = mysql_query("SELECT sid FROM availblesensors WHERE sid='$sid'");
$count = mysql_num_rows($sensorcheck);
if ($count != 0) {
die("You add this Sensor ID before!");
}
if ($sid && $Desc) {
mysql_query("INSERT INTO availblesensors ('$sid','$Desc')");
// success
die("You have add new sensor Successfully !! <a href='admin.php'>click here to return to admin page</a> or Here to
<a href='gotoaddsensor.php'>add new sensor</a>");
} else {
echo "<h3><font color='red'>Please fill in <b>all</b> feilds!</font></h3>";
}
}
?>




<form action="gotoaddsensor.php" method="post" class="one">

<div class="info">

<center><div>Please add availble sensors with a few description of it if you need</div></center><br/>
</div>


<div><b><label for="sid">Sensor ID</label>:</b>
<input name="sid" value="" id="sid" type="text" size="15"/> </div>
<br />
<div><b><label for="password">Description</label>:</b>
<input name="Desc" value="" id="Desc" type="text" size="40"/></div>
<br />

<div id="login-button">
<input name="submit" type="submit" value="submit" />
<input type="reset" value="clear" />
</div>

</form>

最佳答案

查询将是

mysql_query("INSERT INTO availblesensors VALUES ('$sid','$Desc')");

不是

mysql_query("INSERT INTO availblesensors ('$sid','$Desc')");`

您在查询中错过了 VALUES 关键字。

关于php - 向MySQL数据库中插入数据(无数据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13819892/

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