How do I check that the php script works? I’m using php -f filename.php email@address.com, but I get errors. The php script is intended to work with an Android app to retrieve data where the email matches a posted email address. Here is the php code:
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
$email= mysql_real_escape_string($_POST['email']);
$result=mysql_query("SELECT * FROM `TableName` WHERE email='$email' ");
if($result){
$num_rows = mysql_num_rows($result);
print(json_encode($num_rows));
}
mysql_close($con);
?>
Or am I not able to test this script from the command line, and instead should use an html file?
Now, for example if I replace the line: $email= "myaddress@nd.edu"; and then type php -f getdbstats.php I get the correct result.
Command line php is a little different. It does not use POST or GET global arrays to store command line parameters. You have to use global variable called $argv which is populated with parameters from the command line. So in you code, email address is stored in the $argv[1] element of the array. $argv[0] is the name of the script.
Read more here:
http://php.net/manual/en/reserved.variables.argv.php