我在下面的代码中编写了此代码以将查询插入到我的数据库中。我已将此 PHP 代码放在同一页面以及 port.php 上。它也不起作用。任何想法或建议都非常感谢。
这是我将数据插入数据库的 PHP 查询
代码:
<?php
//connect to DB
print_r($_POST);
ini_set('display_errors', 1); //<- here you can switch on and off the error reporting 0 / 1 - makes life easy ;)
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$debug=1;
$host = "localhost"; $username = "root"; $password = "mysqlr00tpa55";
try {
$myconnection = new PDO("mysql:host=$host;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$myconnection ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['insert'])){
$vorname = $_POST['vorname'];
$nachname = $_POST['nacname'];
$email = $_POST['email'];
$telefon = $_POST['telefon'];
$created = $_POST['created']; //geburtstag
$plz = $_POST['plz'];
$ort = $_POST['ort'];
$strasse = $_POST['strasse'];
$hnr = $_POST['hnr'];
$adrZus = $_POST['adrZus'];
$pdoQuery = "INSERT INTO `Port_Owner`(`vorname`, `nachname`, `email`, `telefon`, `created`, `plz`, `ort`, `strasse`, `hnr`, `adrZus`)
VALUES (:vorname,:nachname,:email,:telefon,:created,:plz,:ort,:strasse,:hnr,:adrZus)";
$pdoResult = $myconnection ->prepare($pdoQuery);
$pdoExec = $pdoResult->execute(array(
":vorname"=>$vorname,
":nachname"=>$nachname,
":email"=>$email,
":telefon"=>$telefon,
":created"=>$created,
":plz"=>$plz,
":ort"=>$ort,
":strasse"=>$strasse,
":hnr"=>$hnr,
":adrZus"=>$adrZus));
if($pdoExec)
当我插入 vorname、nachname 和其他字段时,它显示“此页面无效”。Somone 在这方面帮助我。提前致谢
青春有我