我有一个注册表单,它通过POST将输入变量移交给我的MySQLi脚本以插入数据库。问题是,每次运行脚本时,尽管E_ALL处于活动状态,我仍然遇到500错误并且没有任何错误详细信息。
我在上一个脚本中遇到了这个问题,最后通过替换所有
解决了这个问题die("error_message");
目前的
echo ("error message);
exit;
但这次没有运气。如果我猜测,问题将在于将变量注入到SQL语句中,尽管Stackoverflow上的过去搜索向我展示了许多使用这种语法的示例。
<?php
if (isset($_SERVER['REQUEST_METHOD']))
{
// define variables
$activation_date = date("Y-m-d H:i:s", strtotime('+13 hours'));
$access = "User";
$status = "Inactive";
$username = mysql_real_escape_string($_POST['username']));
$password1 = mysql_real_escape_string($_POST['password1']);
$password2 = mysql_real_escape_string($_POST['password2']);
$password_md5 = md5($password1);
$property_name = mysql_real_escape_string($_POST['property_name']);
$gpa_email = mysql_real_escape_string($_POST['GPA_Email']);
$holidex = mysql_real_escape_string($_POST['holidex']);
$gm = mysql_real_escape_string($_POST['General_Manager']);
$gm_email = mysql_real_escape_string($_POST['GM_Email']);
$address1 = mysql_real_escape_string($_POST['Address1']);
$address2 = mysql_real_escape_string($_POST['Address2']);
$zip = mysql_real_escape_string($_POST['ZIP']);
$city = mysql_real_escape_string($_POST['City']);
$state = mysql_real_escape_string($_POST['State']);
$country = mysql_real_escape_string($_POST['Country']);
$phonecc = mysql_real_escape_string($_POST['Phone_CC']);
$phone = mysql_real_escape_string($_POST['Phone']);
}
else
{
echo ("<h2>Ooops...</h2><p>Well, seems like something went wrong. Are you sure you filled out all the fields? Perhaps you would like to <a href=\"./register.php\" onclick=\"window.history.go(-1); return false;\">[GO BACK]</a> and have another look?<br /><br />If you think something else seems to be the problem, how about you drop me a note via the <a href=\"./contact.php\">Contact page</a> and I will see how I can help.</p>");
exit;
}
// check whether passwords are a match
if ($_POST['password1']!= $_POST['password2'])
{
echo ("<h2>Ooops...</h2><p>Well, it seems like your previously entered passwords dont match. Perhaps you would like to <a href=\"./register.php\" onclick=\"window.history.go(-1); return false;\">[GO BACK]</a> and have another look?<br /><br />If you think something else seems to be the problem, how about you drop me a note via the <a href=\"./contact.php\">Contact page</a> and I will see how I can help.</p>");
exit;
}
// get login credentials
include "../scripts/MySQL/connect_db.php";
// Create connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
trigger_error("<h2>Ooops...</h2><p>Connection to database failed: " . $conn->connect_error . "<br /><br />This is really not good. Please send me a message via the <a href=\"./contact.php\">Contact page</a> and I will see how I can help.</p>");
}
// Check if holidex code already exists
$sql = "SELECT * FROM GPA_properties WHERE holidex='".$holidex."'");
if(mysqli_num_rows($sql) > 0)
{
echo ("<h2>Ooops...</h2><p>Well, it seems like your property is already signed up. In case you forgot your ID and Password, have a look at the <a href=\"./login.php\">Login page</a> and click on the FORGOT PASSWORD link.<br /><br />If you think something else seems to be the problem, how about you drop me a note via the <a href=\"./contact.php\">Contact page</a> and I will see how I can help.</p>");
exit;
}
// Write content into database
$sql = "INSERT INTO GPA_properties (Activation_Date, Access, Status, Holidex, Username, Password, Property_Name, GPA_Distribution_Email, General_Manager, GM_Email, Address_1, Address_2, ZIP, City, State, Country, Phone_CC, Phone)
VALUES ('".$activation_date."', '".$access."', '".$status."', '".$holidex."', '".$username."', '".$password_md5."', '".$property_name."', '".$gpa_email."', '".$gm."', '".$gm_email."','".$address1."', '".$address2."', '".$zip."', '".$city."', '".$state."', '".$country."', '".$phone."', '".$phone_cc."')";
if (mysqli_query($conn, $sql)) {
echo "<h2>Hooray! Registration complete!</h2><p>Your registration has been submitted successfully. Please wait until your request has been verified and your account activated.</p>";
} else {
echo ("Error: " . $sql . "<br>" . mysqli_error($conn));
exit;
}
// close connection
$conn->close();
?>
&#13;
有什么想法吗? 感谢
编辑:由于有人标记这是重复的,让我解释为什么这些问题是不同的:
我的网站上的任何日志都没有错误日志。 E_ALL有效,但没有回报;
在网站上的另一个实例中使用了完全相同的MySQL脚本,但仅在此处我无法运行它。
我已经进行了大量的bug搜索,并运行了不同的脚本段来指出问题所在,但没有成功。
解:
事实证明,根本没有收到任何错误消息的问题与if (isset($_SERVER['SERVER_REQUEST']))
有关,我将其更改为if ($_SERVER["REQUEST_METHOD"] == "POST") {
,然后最终出现错误。
Chrome似乎拒绝加载页面,以防万一遇到与$ _SERVER变量相关的任何错误,我不知道为什么我之前的语句提出了那个标志,但替代方案解决了问题并允许我运行其余的剧本。