I am trying to insert into DB getting data from URL but doesn't work
here the link http://localhost/test/recevier.php?heat1=33&heat2=33&heat3=33&gas=33&motion=33
here my db.php file
$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();
}
and here my recevier.php file
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();
and this is the table I am trying to insert into
the 'echo' statement to check if the file get the data & he git it
What does the error says? Anyway I notice there's a typo in this line:
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, mation,
Should it be :
$vars = $conn->prepare("INSERT INTO var(entryId, heat1, heat2, heat3, gas, motion, personId) VALUES (:zentryId, :zheat1, :zheat2, :zheat3, :zgas, :zmotion, :zpersonId)");