【问题标题】:trying to insert into DB from URL but doesn't work [duplicate]尝试从 URL 插入数据库但不起作用 [重复]
【发布时间】: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 它

enter image description here

【问题讨论】:

    标签: php mysql url pdo get-request


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢你我不敢相信我没有注意到
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 2016-01-21
    • 2017-10-07
    • 2022-01-23
    • 2011-09-12
    相关资源
    最近更新 更多