2016-11-12 126 views
0

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

<?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); 


    ?> 
+0

看看你的http服务器错误日志文件。这就是你可以简单地阅读问题所在而不是必须_guess_的地方。 – arkascha

+0

可否请您在echo'Not Inserted'之后放置此行; printf(“Message d'erreur:%s \ n”,mysqli_error($ connection)); 2.把它作为你的文件的第一行dbConnection.php:error_reporting(E_ALL); – erwan

+0

第一件事就是不需要选择数据库mysqli_connect()第四个参数是数据库名称self。 –

回答

1
$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')"; 
+0

非常感谢Dinesh Bhojvoni ..你节省了我的时间...... :) –

相关问题