无法使用http post和PHP在数据库中保存值
我正在尝试编写一个PHP代码,用于在数据库中保存温度数据和时间戳,并在表中显示值。温度数据通过http post发送到数据库 代码如下: index.php(显示表格)无法使用http post和PHP在数据库中保存值,php,mysql,database,Php,Mysql,Database,我正在尝试编写一个PHP代码,用于在数据库中保存温度数据和时间戳,并在表中显示值。温度数据通过http post发送到数据库 代码如下: index.php(显示表格) Arduino温度计控制面板 温度检测器 温度是: 温度 时间戳 地位 connect.php(连接到mysql服务器) 您的插入查询错误。看起来您可能混淆了insert和update的语法。对于插入,您永远不会执行类似value= $sql = "INSERT INTO temptrac_temp (ID, temp, t
Arduino温度计控制面板
温度检测器
温度是:
温度
时间戳
地位
connect.php(连接到mysql服务器)
您的插入查询错误。看起来您可能混淆了insert和update的语法。对于插入,您永远不会执行类似value=
$sql = "INSERT INTO temptrac_temp (ID, temp, timestamp) VALUES (NULL, temp=?, CURRENT_TIMESTAMP)"
您可以这样编写查询
$sql = "INSERT INTO temptrac_temp (ID, temp, timestamp) VALUES (NULL, ?, CURRENT_TIMESTAMP)"
然后,您可以做任何您需要做的事情来将一个实际值细分到?在查询中
Connection.php
PAGE
index.php
PAGE
Arduino温度计控制面板
温度检测器
温度是:
温度
时间戳
地位
输出
阅读此脚本以将数据添加到服务器中。希望能有帮助。如果有任何疑问,请告诉我 已经像你告诉我的那样试过了。不起作用。但我不清楚这句话是怎么说的。我看到许多版本的=?或者只有?,一些带有:name或:value.cool!你有没有尝试过制作一个页面,或者有一种PHP编辑器,在线调试器?兄弟,我在我的本地机器上做过…)超级tnx!你太棒了。。。。无论如何,我仍然想知道为什么还没有一个好的PHP调试在线。有很多网站。只需谷歌一下。比如:http://phpio.net/
,http://phpfiddle.org/
,http://www.writephponline.com/
,https://www.codechef.com/ide
,http://phptester.net/
,http://sandbox.onlinephpfunctions.com/
,http://codepad.org/
。。etc@AndreaMancini .. 如果你得到了Ans,那么请。。在问题的右边打勾,然后投票:)随时乐意帮忙!!
<?php
include("connect.php");
$link = Connection();
$temp = mysqli_real_escape_string($_POST["temp"]);
//$lat =$_POST["lat"];
//$lng =$_POST["lng"];
$sql = "INSERT INTO temptrac_temp (ID, temp, timestamp) VALUES (NULL, temp=?, CURRENT_TIMESTAMP)";
$stmt = $link->prepare($sql);
$stmt->bind_param("d", $temp);
$stmt->execute();
//mysqli_query($link, $query);
$stmt->close();
$link->close();
header("Location: index.php");
exit();
?>
$sql = "INSERT INTO temptrac_temp (ID, temp, timestamp) VALUES (NULL, temp=?, CURRENT_TIMESTAMP)"
$sql = "INSERT INTO temptrac_temp (ID, temp, timestamp) VALUES (NULL, ?, CURRENT_TIMESTAMP)"
<?php
function Connection(){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
return $conn;
}
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "INSERT INTO temptrac_temp (ID, temp, timestamp) VALUES (NULL,'?',CURRENT_TIMESTAMP)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
header("Location: index.php");
$conn->close();
?>
<?php
include("connection.php");
$link=Connection();
$sql="SELECT * FROM `temptrac_temp` ORDER BY `timestamp` DESC";
$result=mysqli_query($link, $sql);
/* determine number of rows result set */
$row_cnt = $result->num_rows;
printf("Result set has %d rows.\n", $row_cnt);
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Arduino thermometer control panel</title>
<link rel="stylesheet" href="./css/index.css?v=1.0">
</head>
<body>
<div class="container">
<p>Temperature Arduino checker</p>
<p>The temperature is:</p>
<table class="normal" border="2" cellspacing="1" cellpadding="1">
<tr>
<td> Temperature </td>
<td> Timestamp </td>
<td> Status </td>
</tr>
<?php
if($result!==FALSE){
while($row = mysqli_fetch_array($result)) {
if($row["temp"] <= 8){
printf("<tr><td> %s</td><td> %s </td><td> Ok! </td></tr>",
$row["temp"], $row["timestamp"]);
}
if($row["temp"] > 8){
printf("<tr><td> %s</td><td> %s </td><td> Alert! </td></tr>",
$row["temp"], $row["timestamp"]);
}
}
mysqli_free_result($result);
mysqli_close($link);
}else{
printf("there is an error");
}
?>
</table>
</div>
</body>
</html>
<?php
include("dbconnect.php");
$SQL= "INSERT INTO tabl1(reading,cost)VALUES(".$_GET["reading"].",".$_GET["cost"].")";
mysqli_query($dbh,$SQL);
header("Location: review_data.php");
?>