这是我的代码:
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$method = $_POST["method"]; //dropdown box
$category = $_POST["category"]; //dropdown box
$email = mysql_real_escape_string($_POST["email"]);
$companyname = mysql_real_escape_string($_POST["companyname"]);
$phone = mysql_real_escape_string($_POST["phone"]);
$address = mysql_real_escape_string($_POST["address"]);
$state = mysql_real_escape_string($_POST["state"]);
$zip = mysql_real_escape_string($_POST["zip"]);
$salt = $email;
$length = 10;
$temporarypassword =
substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
0, $length);
$temp_encrypted_password = sha1($salt.$temporarypassword);
$addcompany = mysql_query("INSERT INTO company (`method`, `category`,
`email`, `password`, `companyname`, `phone`, `address`, `state`, `zip`, `ratingcount`,
`ratingscore`, `usage`, `date`)
VALUES
('$method','$category','$email','$temp_encrypted_password',
'$companyname','$phone','$address','$state','$zip','0','0','0',CURDATE()) ")
or die(mysql_error());
if (mysql_fetch_array($addcompany)) {
$to = "$email";
$subject = "Your Temporary Password";
$message = "Your temporary password is: <b>$temporarypassword;</b>. Sign in and
update your password as soon as possible.";
$header = "From: email@gmail.com\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
mail($to,$subject,$message,$header);
$message = "Company Added";
}
}
}
因此,sql 语句执行得很好,并按照我的需要输入到我的数据库中。但是,如果 $addcompany 返回 true 的 IF 语句必须返回 false,因为语句中的任何内容都不会执行。我在我网站的其他部分以这种方式对 mysql_fetch_array 使用这种检查,它工作正常,所以我很好奇为什么在这种情况下它没有返回。
仅供参考,我正在为那些会说的人研究 PDO。大声笑我已经在今天的前一篇文章中对此进行了扩孔。
谢谢你的时间,我很感激。