PHP在提交后插入MySQL html表单

时间:2019-05-01 19:57:08

标签: php mysql

我正在尝试使用php脚本将数据插入数据库,但是在新页面上->之后出现php脚本中的文本:

setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$query = $connect->prepare("insert into konkurs(name,mail) values(?, ?)"); 
$query->bindValue(1, $name); $query->bindValue(2, $mail); 
try {
    $query->execute();
} catch (PDOException $e) { 
    die($e->getMessage()); 
}

我尝试使用

  

php -v

命令行中的

命令,但重试该程序无法识别。

这是我的html代码:

<form method="post" action="input.php">
            <input type="text" class="form-control" name="txtName" maxlength="20" required style="margin-bottom:20px">
            <input type="email" class="form-control" name="txtEmail" aria-describedby="emailHelp" required style="margin-bottom:20px">
            <textarea class="form-control" name="txtDescription" maxlength="500" required style="margin-bottom:20px" TextMode="MultiLine" Rows="5"></textarea>
            <br>
            <input type="submit" class="btn btn-success"  id="btnsubmit" value="Zgłoś się" />
        </form>

这是我的php代码:

<?php
$name = $_POST['txtName']; 
$mail = $_POST['txtEmail']; 
$connect = new PDO("mysql:host=46******03;dbname=3***b", "3***b", "J****0-");
$connect->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$query = $connect->prepare("insert into konkurs(name,mail)
values(?, ?)");
$query->bindValue(1, $name);
$query->bindValue(2, $mail);
try {
     $query->execute();
} catch (PDOException $e) {
     die($e->getMessage());
}
?>

0 个答案:

没有答案