未捕获错误:在C:\ xampp \ htdocs \ register.php中调用未定义函数mysql_connect():22

时间:2017-01-17 17:21:52

标签: php mysql json mysqli xampp

我是使用PHP的新手,我在解决此问题时遇到问题。请帮帮我们。我正在尝试为我的Android应用程序创建Web服务,我已使用Advanced Rest Client来解析JSON值。但我这样做并不成功。我已尝试使用所有可用的解决方案,请有人只是更改我的代码并尝试使其工作。

错误是:

  

未捕获错误:调用未定义的函数mysql_connect()   C:\ xampp \ htdocs \ PhpProject1 \ index.php:26堆栈跟踪:#0 {main}抛出   第26行的C:\ xampp \ htdocs \ PhpProject1 \ index.php

这是我的代码:

        <?php

        $jsoninput = file_get_contents('php://input');
        $jsonstring = json_decode($jsoninput,TRUE);       

        $email = $jsonstring["email"];
        $pass = $jsonstring["pwd"];
        $name = $jsonstring["name"];
        $gender = $jsonstring["gender"];
        $dob = $jsonstring["dob"];
        $area = $jsonstring["area"];
        $phone = $jsonstring["phone"];

        mysql_connect("localhost","root","");     
        mysql_select_db("honest-e");
        $query = "INSERT INTO `citizen_details_registration`(`Citizen_regid`, `citizen_name`, `citizen_gender`, `citizen_dob`, `citizen_area`, `citizen_phoneno`) VALUES ('null','$name','$gender','$dob','$area','$phone')";
        $norow = mysql_query($query);        
        if($norow>0)
        {
            echo "Success registration";
        }
        else
        {
            echo "Try again registration";
        }


        $query2 = "SELECT `Citizen_regid` FROM `citizen_details_registration` WHERE citizen_name = '$name' AND citizen_dob = '$dob'";
        $num = mysql_query($query2);
        $id =0;
        while($row = mysql_fetch_array($num,MYSQLI_ASSOC))
        {
            $id=$row['Citizen_regid'];
        }

        $query3 = "INSERT INTO `citizen_details_login`(`citizen_logid`, `citizen_email`, `citizen_password`, `citizen_regid`) VALUES ('null','$email','$pass','$id')";
        $norow1 = mysql_query($query3);        
        if($norow1>0)
        {
            echo "Success login";
        }
        else
        {
            echo "Try again login";
        }   
    ?>

尝试使用mySQLi:

        <?php

        $jsoninput = file_get_contents('php://input');
        $jsonstring = json_decode($jsoninput,TRUE);       

        $email = $jsonstring["email"];
        $pass = $jsonstring["pwd"];
        $name = $jsonstring["name"];
        $gender = $jsonstring["gender"];
        $dob = $jsonstring["dob"];
        $area = $jsonstring["area"];
        $phone = $jsonstring["phone"];


        $mysqli = new mysqli("localhost", "root", "", "honest-e");
        $query1 = $mysqli->query("INSERT INTO `citizen_details_registration`(`Citizen_regid`, `citizen_name`, `citizen_gender`, `citizen_dob`, `citizen_area`, `citizen_phoneno`) VALUES ('null','$name','$gender','$dob','$area','$phone')");

        if($query1>0)
        {
            echo "Successful registration!";
        }
        else
        {
            echo "Try again registration!";
        }

        $query2 = $mysqli->query("SELECT `Citizen_regid` FROM `citizen_details_registration` WHERE citizen_name = '$name' AND citizen_dob = '$dob'");
        $id=0;
        while( $row = $query2->fetch_assoc())  
        {
            $id=$row['Citizen_regid'];
        }

        $query3 = $mysqli->query("INSERT INTO `citizen_details_login`(`citizen_logid`, `citizen_email`, `citizen_password`, `citizen_regid`) VALUES ('null','$email','$pass','$id')");
        if($query3>0)
        {
            echo "Successful login";
        }
        else
        {
            echo "Try again login";
        }        

我已经在mySQLi的帮助下尝试了这个解决方案,即使我的程序运行成功但不幸的是我的数据库没有变化。

1 个答案:

答案 0 :(得分:-1)

在PHP7中删除了

mysql _ * 函数!
你可能在XAMPP中有一个php7请使用PDO和......感受光源的力量:)
解决了这里。 https://stackoverflow.com/a/34579855/7349445