【发布时间】:2018-05-24 02:09:39
【问题描述】:
我正在尝试插入数据库,从 URL 获取数据但不起作用
这里是链接 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();
这是我要插入的表格
'echo' 语句来检查文件是否获取数据 & 他 git 它
【问题讨论】:
标签: php mysql url pdo get-request