php - 表单提交按钮不起作用

时间:2018-04-26 22:26:14

标签: php html forms validation

我想做简单的CRUD操作。我为此创建了一个表单,我正在进行数据输入。但是当我刷新页面时,它会自动注册。我试图用“isset”函数解决这个逻辑错误,但事实并非如此。错误在哪里?

$ad = isset($_POST['ad']) ? $_POST['ad'] : '';
$soyad = isset($_POST['soyad']) ? $_POST['soyad'] : '';
$adres = isset($_POST['adres']) ? $_POST['adres'] : '';
$tur = isset($_POST['tur']) ? $_POST['tur'] : '';


if(isset($_POST["submit"])){


    try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        // bağlantı özelliklerinden hata modunu aktifleştirdik
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "INSERT INTO `kisiler` (`ad`, `soyad`, `adres`, `tur`) VALUES ('$ad', '$soyad', '$adres', '$tur')";
        // use exec() because no results are returned
        $conn->exec($sql);
        echo "işte şimdi oldu";
        }
    catch(PDOException $e)
        {
        echo $sql . "<br>" . $e->getMessage();
        }

    $conn = null;
    }

<html>
    <body>
        <form action="" method="POST">
        <p> 
        Ad:    <input type="text" name="ad"/>
        Soyad: <input type="text" name="soyad"/>
        Adres:<input type="text" name="adres"/>
        Tur: <input type="text" name="tur"/>
        <input type="submit"name="submit"/>
        </p>
        </form>
    </body>

0 个答案:

没有答案