除了Connection

时间:2017-01-15 15:38:59

标签: php android mysql

我正在通过查看一些视频教程在android studio中开发一个登录和注册应用程序,并且PHP脚本是100%,如教程中那样,它第一次正在工作,然后现在它无法工作。我可以'找出出了什么问题。我是php和android的新手

在教程中,它纯粹是有效的。 教程链接>> Registration app tutorial

花了两天多的时间来连接数据库,仍然停留在最后,最后进入stackoverflow,希望获得良好的解决方案或指导。感谢

init.php ,用于连接,连接成功

<?php
$host = "localhost";
$user = "blood";
$password = "rifkan123";
$dbname = "userdb";

$con = mysqli_connect($host,$user,$password,$dbname);

if(!$con)
{
die("Error in Database Connection".mysqli_connect_error());

}
else
{
Echo "<h3> Database Connection Success !";
}

?>

login.php 登录脚本

<?php
$email = $_POST["email"];
$pass = $_POST["password"];
require "init.php";

$query = "Select * userinfo where email like. '".$email."';";
$result = mysqli_query($con,$query);

if(mysqli_num_rows($result)>0)
{
$response = array();
$code ="login_true";
$row = mysqli_fetch_array($result);
$name = $row[0];
$message ="Login Success ! Welcome ".$name;
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode(array(server_response=>$response));    
}
else
{
$response = array();
$code ="login_false";
$message ="Login Failed ! Try Again";
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode(array(server_response=>$response));    
}
mysqli_close($con);
?>

register.php 用于用户注册

<?php

$name = $_POST["name"];
$email = $_POST["email"];
$pass = $_POST["password"];
require "init.php";

$query = "select * from userinfo where email like '".$email."';";
$result = mysqli_query($con,$query);

if(mysqli_num_rows($result)>0)
{

$response = array();
$code = "reg_false";
$message = "User Already Exist !";
array_push($response,array("code"=>$code,"message"=>$message));
echo json_encode(array("server_response"=>$response));

}
else
{
$query = "insert into userinfo      values('".$name."','".$email."','".$pass."');";
$result = mysqli_query($con,$query);

if(!$result)
{
    $response = array();
    $code = "reg_false";
    $message = "Registration Failed, Try Again!";
    array_push($response,array("code"=>$code,"message"=>$message));
    echo json_encode(array("server_response"=>$response));
}
else
{
    $response = array();
    $code = "reg_true";
    $message = "Registration Success, Login to Continue!";
    array_push($response,array("code"=>$code,"message"=>$message));
    echo json_encode(array("server_response"=>$response));
}
mysqli_close($con);
}
?>

我在登录脚本中错过了FROM,并在添加后检测到新的错误 Screen shot new Error

1 个答案:

答案 0 :(得分:0)

您忘记了login.php

中的FROM子句

下面

  $query = "Select * from userinfo where email like. '".$email."';";

另请考虑添加%%

相似