database: mobiledb
table androidlogin
columns - id,user,pass
<?php
//Create fields for database , server , username ,password, database
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbdb = "mobiledb";
//Connect to mySQL
$connect = mysql_connect($dbhost , $dbuser , $dbpass)
or die("connection error");
//select the database
mysql_select_db($dbdb)or die("database selection error");
//retrieve the login details via post
$username = $_POST['username'];
$password = $_POST['password'];
//query the table android login
$query = mysql_query("SELECT * FROM androidlogin WHERE user = '$username' AND
pass = '$password'");
//check if there is any results returned
$num = mysql_num_row($query);
//if a record was found matching the details entered in the query
if($num==1)
{
//create a while loop that places the returned data into an array
while($list = mysql_fetch_assoc($query))
{
//store the returned data into variable
$output = $list;
//encode the data in JSON format
echo json_encode($output);
}
//close the connection
mysql_close();
}
?>
or
<?php
//Create fields for database , server , username ,password, database
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbdb = "mobiledb";
//Connect to mySQL
$connect = mysql_connect($dbhost , $dbuser , $dbpass)
or die("connection error");
//select the database
mysql_select_db($dbdb)or die("database selection error");
//retrieve the login details via post
$username = $_POST['username'];
$password = $_POST['password'];
//query the table android login
$query = mysql_query("SELECT * FROM androidlogin WHERE user = '$username' AND pass = '$password'");
//create a while loop that places the returned data into an array
while($list = mysql_fetch_assoc($query))
{
//store the returned data into variable
$output[] = $list;
//encode the data in JSON format
echo json_encode($output);
}
//close the connection
mysql_close($connect);
?>
No comments:
Post a Comment