1

I am developing a login and registration application in android studio by looking at some of video tutorials,and the php scripts are 100% as in the tutorial and it was working at first time, then now its not working.I can't identify what's gone wrong.. I am new to php and android

In the tutorial it's purely working. Tutorial link >>Registration app tutorial

spent more than two days for linking database, still stucked over, finally into stackoverflow, Hope for good Solution or Guidance. Thanks

init.php which is for Connection, and connection Success

<?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 Script for login

<?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 for user registration

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

I have missed the FROM in login script and after adding it new error detected Screen shot new Error

  • 1
    You need to be clearer. "Not working" tells us nothing. What's happening- are they not running at all? Not returning the right results? If so what are they doing? – Gabe Sechan Jan 15 '17 at 15:41
  • I made a HTML file to test both registration and login when i run it php scripts displays on the browser –  Jan 15 '17 at 15:46
  • *Not working* could mean errors, no output at all, or not getting the expected result. Be clear please. – Fevly Pallar Jan 15 '17 at 15:46
  • If PHP scripts display on the browser, there's a configuration problem in your server. Its treating them as static files rather than programs to run. – Gabe Sechan Jan 15 '17 at 15:47
  • Then what you need to read is this : http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page – Fevly Pallar Jan 15 '17 at 15:48
  • script displays as it is does not give a response the registration success or failed , –  Jan 15 '17 at 15:48
  • But at first time everything worked fine, even the database got updated, for this same code –  Jan 15 '17 at 15:50
  • @RifkanRazak make sure you're opening it using the web server (http://localhost/your/path) and not directly (c:\some\path\yourfile.php) – JimL Jan 15 '17 at 15:58
  • @JimL Yah Its open via server –  Jan 15 '17 at 16:03
  • @RifkanRazak in your screenshot it isn't – JimL Jan 15 '17 at 16:04
  • @JimL when i click the Login button the file open as in the screen shot –  Jan 15 '17 at 16:15
  • To narrow down the source of the problem it would be wise to test each individual piece of code to see where the problem might lie. – Robert Jan 15 '17 at 16:25

1 Answers1

0

You forgot FROM clause in login.php

Here

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

Also consider to add %% with like

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109