检查if语句是否给出了错误的结果?

时间:2014-10-07 01:26:57

标签: php mysql database

这是代码

<?php
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$phone = $_POST['phone'];
$referral = $_POST['refer'];
$referred = false;
mysql_connect("localhost","username","password") or die (mysql_error());
mysql_select_db("database") or die ("Cannot connect to database");
$query = mysql_query("Select * from member"); 
while($row = mysql_fetch_array($query)) 
{
  $table_users = $row['username'];
  $table_email = $row['email'];
  $table_phone = $row['phone'];
  if($referral == $table_users)
  {
    $referred = true;
  }
  if($username == $table_users || $email == $table_email || $phone == $table_phone)
  {
    $bool = false;
  }
}
if(($bool))
{
  $username = mysql_real_escape_string($username);   
  mysql_query("INSERT INTO member (username, password, email, phone, refer) VALUES ('$username', '$password', '$email', '$phone', '$referral')"); 
  if($referred)
  {
    $from="Sent from test";
    $subject="New user referred.";
    $message="A new user " . $username . " has been referred by " . $referral . "Please stay updated. ";
    mail("mymail", $subject, $message, $from);
  }
  $_SESSION['login'] = true;
  echo "Thank you for registering with us.You can <a href=\"index.php\">login</a> now to start earning.";
}

如果引荐代码字段为空或者它与数据库中的任何值都不匹配,它仍会发送 邮件。那么,这里发生了什么?我添加了一些代码。我早些时候留下了一部分。

1 个答案:

答案 0 :(得分:0)

此声明if($referral == $table_users)看起来并不合适。您尚未在代码中的任何位置设置$referral变量。