尝试从URL插入数据库但不起作用

时间:2017-12-10 10:32:32

标签: php mysql url pdo get-request

我正在尝试插入数据库从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 it

enter image description here

1 个答案:

答案 0 :(得分:0)

错误是什么?无论如何,我注意到这一行有一个错字:

$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)");