PHP向mysql注册后返回错误500

时间:2018-12-10 00:34:36

标签: php mysql mysqli

因此,我试图通过使用android平台从用户检索值并将用户凭据注册到基本的mySQL数据库中进行基本的注册活动。当我运行responseListener时,register.php页面返回服务器错误500,因此我被认为是我的php脚本有缺陷。

register.php

<?php
error_reporting(-1); // reports all errors
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
try{
    $con = mysqli_connect("con","user","pass","db"); 
    if($_SERVER["REQUEST_METHOD"] == "POST") {
        $email = mysqli_real_escape_string($con,$_POST['email']);
        $username = mysqli_real_escape_string($con,$POST['username']);
        $name = mysqli_real_escape_string($con,$_POST['name']);
        $password = mysqli_real_escape_string($con,$_POST['password']);
        $response = array();
        $sql = "Select * from Registration where email = '$email' or username = '$username'";
        $result = mysqli_query($con, $sql);
        $user = mysqli_fetch_assoc($result);
        if(($user['username'] === $username) or ($user['email'] === $email)){
            $response["success"] = false;
            }
        else{
            $myhash = password_hash($password, PASSWORD_DEFAULT);
            $sql1 = "insert into Registration (email, username, name, password) values('$email', '$username', '$name', '$myhash')";
            $insert = mysqli_query($con, $sql1);
            $validation = mysqli_num_rows($insert);
            if($validation == 1){
                $response["success"]= true;
                }
            else{
                $response["success"]= false;
                }
                }
        echo json_encode($response);
        die($con);
        }
    }
    catch(error $e){
        $response = array();
        $reponse["success"] = false;
        $response["error"] = $e;
        echo json_encode($response);
        die($con);
        }
?>

感谢您的帮助

0 个答案:

没有答案