如何在PHP中将值作为POST传递而不是硬编码值?

时间:2017-08-24 17:36:35

标签: php mysql sql

<?php
$host='localhost';
$username='root';
$pwd='';
$db="singlover";


$con=mysqli_connect($host,$username,$pwd,$db) or die('Unable to connect');

if(mysqli_connect_error($con))
{
  echo "Failed to Connect to Database ".mysqli_connect_error();
}
$sql="SELECT * FROM users u, address a WHERE a.email=u.email AND a.country LIKE (SELECT country FROM address WHERE email = 'ta.....@gmail.com' );";
$result=mysqli_query($con,$sql);
if($result)
{
  while($row=mysqli_fetch_array($result))
  {
    $data[]=$row;
  }

  print(json_encode($data));
}
mysqli_close($con);
?>

我确实需要通过POST方法传递电子邮件,我将嵌套查询中的电子邮件作为硬编码值传递,它返回真实数据,但我将如何执行它?

<?php
$host='localhost';
$username='root';
$pwd='';
$db="singlover";

$email = $_POST["email"];

$con=mysqli_connect($host,$username,$pwd,$db) or die('Unable to connect');

if(mysqli_connect_error($con))
{
  echo "Failed to Connect to Database ".mysqli_connect_error();
}
$sql="SELECT * FROM users u, address a WHERE a.email=u.email AND a.country LIKE (SELECT country FROM address WHERE email = $email );";
$result=mysqli_query($con,$sql);
if($result)
{
  while($row=mysqli_fetch_array($result))
  {
    $data[]=$row;
  }

  print(json_encode($data));
}
mysqli_close($con);
?>

我已经尝试过这个脚本,但它没有任何回报。 非常感谢你的帮助。

0 个答案:

没有答案