这是将数据输入到mysql数据库中的php文件。当我运行它时,浏览器显示“已成功选择连接成功,正在执行的文件未插入内部”。但不会显示任何错误。并且数据不会插入数据库中。此代码有什么问题。
* dbConnection.php

  <?php
        $dbhost="localhost";
        $dbuser="root";
        $dbPassword="123";
        $database="medicalcenter";

    $connection = mysqli_connect($dbhost,$dbuser,$dbPassword) or die("unable to connect");
         if($connection){
            echo 'connected successfully ';
        }else{
            echo 'not connected';
        }

        $dbSelect=mysqli_select_db($connection,$database);
        if($dbSelect){
            echo 'selected successfully';
        }else{
            echo 'not selected';
        }
?>


* insert.php

<?php
    include 'dbConnection.php';
    echo "Executing inside file";
    $firstName = filter_input(INPUT_POST,'firstname');
    $secondName = filter_input(INPUT_POST,'lastname');
    $address1 =filter_input(INPUT_POST,'address1');
    $address2 =filter_input(INPUT_POST,'address2');
    $city =filter_input(INPUT_POST,'city');
    $email =filter_input(INPUT_POST,'email');
    $age =filter_input(INPUT_POST,'age');
    $gender =filter_input(INPUT_POST,'gender');


    $sql= "INSERT INTO    patient(FirstName,LastName,AddressLine1,AddressLine2,City,Email,Age,Gender) VALUES ('$firstName','$secondName','$address1','$address2','$city',$email','$age','$gender')";


    if(mysqli_query($connection,$sql)){
        echo 'Inserted successfully';
    }else{
        echo 'Not Inserted';
    }

    mysqli_close($connection);


  ?>

最佳答案

  $sql= "INSERT INTO    patient(FirstName,LastName,AddressLine1,AddressLine2,City,Email,Age,Gender) VALUES ('$firstName','$secondName','$address1','$address2','$city',$email','$age','$gender')";


在发送电子邮件之前,请检查您忘记了'的上述行,请与以下行进行检查。希望对您有帮助。

$sql= "INSERT INTO    patient(FirstName,LastName,AddressLine1,AddressLine2,City,Email,Age,Gender) VALUES ('$firstName','$secondName','$address1','$address2','$city','$email','$age','$gender')";

10-08 09:09
查看更多