试图从 URL 插入数据库但不起作用
trying to insert into DB from URL but doesn't work
我正在尝试插入数据库以从 URL 获取数据,但不起作用
这里是link
http://localhost/test/recevier.php?heat1=33&heat2=33&heat3=33&gas=33&motion=33
这里是我的 db.php 文件
$dsn = "mysql:host=127.0.0.1;dbname=test;";
$user = 'root';
$pass = '';
try {
$conn = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
echo 'field to connect' . $e->getMessage();
}
这是我的 recevier.php 文件
include "db.php";
$heat1 = $_GET['heat1'];
$heat2 = $_GET['heat2'];
$heat3 = $_GET['heat3'];
$gas = $_GET['gas'];
$motion = $_GET['motion'];
$personId = 1;
echo $heat1;
echo $heat2;
echo $heat3;
echo $gas;
echo $motion;
$entryId = 3;
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, mation, personId) VALUES (:zentryId, :zheat1, :zheat2, :zheat3, :zgas, :zmotion, :zpersonId)");
$vars->bindParam(':zentryId', $entryId);
$vars->bindParam(':zheat1', $heat1);
$vars->bindParam(':zheat2', $heat2);
$vars->bindParam(':zheat3', $heat3);
$vars->bindParam(':zgas', $gas);
$vars->bindParam(':zmotion', $motion);
$vars->bindParam(':zpersonId', $personId);
$vars->execute();
这是我要插入
的 table
检查文件是否获取数据的'echo'语句他git它
enter image description here
错误说明了什么?不管怎样,我注意到这一行有一个错字:
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, mation,
应该是:
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, motion, personId) VALUES (:zentryId, :zheat1, :zheat2, :zheat3, :zgas, :zmotion, :zpersonId)");
我正在尝试插入数据库以从 URL 获取数据,但不起作用
这里是link http://localhost/test/recevier.php?heat1=33&heat2=33&heat3=33&gas=33&motion=33
这里是我的 db.php 文件
$dsn = "mysql:host=127.0.0.1;dbname=test;";
$user = 'root';
$pass = '';
try {
$conn = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
echo 'field to connect' . $e->getMessage();
}
这是我的 recevier.php 文件
include "db.php";
$heat1 = $_GET['heat1'];
$heat2 = $_GET['heat2'];
$heat3 = $_GET['heat3'];
$gas = $_GET['gas'];
$motion = $_GET['motion'];
$personId = 1;
echo $heat1;
echo $heat2;
echo $heat3;
echo $gas;
echo $motion;
$entryId = 3;
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, mation, personId) VALUES (:zentryId, :zheat1, :zheat2, :zheat3, :zgas, :zmotion, :zpersonId)");
$vars->bindParam(':zentryId', $entryId);
$vars->bindParam(':zheat1', $heat1);
$vars->bindParam(':zheat2', $heat2);
$vars->bindParam(':zheat3', $heat3);
$vars->bindParam(':zgas', $gas);
$vars->bindParam(':zmotion', $motion);
$vars->bindParam(':zpersonId', $personId);
$vars->execute();
这是我要插入
的 table检查文件是否获取数据的'echo'语句他git它
enter image description here
错误说明了什么?不管怎样,我注意到这一行有一个错字:
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, mation,
应该是:
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, motion, personId) VALUES (:zentryId, :zheat1, :zheat2, :zheat3, :zgas, :zmotion, :zpersonId)");