为什么我的PHP文件出现500内部错误?

时间:2016-02-05 21:20:48

标签: php html mysql google-chrome

我创建了一个带有HTML表单的用户注册页面。我刚刚完成PHP文件以将数据提交到MySQL数据库。

我已经检查过phpMyAdmin已连接到数据库并正常工作。

据我所知,MySQL查询和其他PHP代码似乎都很好,但是我在PHP代码页面上出现内部错误。我使用include函数将PHP文件包含在HTML文件中,HTML注册页面和PHP文件都在Chrome上返回以下错误:

  

“网站在检索[WEB ADDRESS]时遇到错误。可能因维护失败或配置不正确。”

我还应该注意到,只有这个页面才能正常运行,网站上的其他页面工作正常,所以它是这个PHP文件的挑剔。我会粘贴代码,但它很长。我以前从来没有得到过PHP文件的普通500错误,我以前做过类似的注册表单和代码,从来没有遇到过这个问题。

非常感谢任何帮助。

代码

<?php
error_reporting(E_ERROR);

//Errors
$password_error = "<div class='login-form-error'>Your passwords didn't match, be careful this time!</div>";
$field_error = "<div class='login-form-error'>You cannot leave any fields blank or use an invalid character.</div>";
$username_error = "<div class='login-form-error'>That username is already taken, make another one.</div>";
$characters_error = "<div class='login-form-error'>Your username cannot contain any special characters.</div>";
$email_error = "<div class='login-form-error'>Your emails didn't match, be careful next time!</div>";
$signedup = "<center><h1>Welcome to the club!</h1><span style='font-size: 24px;'>Your account is all ready, <a href='/client/sign-in' style='color: #212121; text-decoration: underline;'>Sign In</a> and set up your profile.</span></center>";
$max_length_error = "<div class='login-form-error'>Your first name or username cannot contain more than 25 characters.</div><br>";
$max_length_password_error = "<div class='login-form-error'>Your password must be between 8 and 30 characters long.</div>";

$reg =@$_POST['reg'];
//Declaring variables to prevent errors
$first_name = "";
$gender = "";
$age = "";
$username = "";
$password = "";
$password2 = "";
$email = "";
$email2 = "";
$date = "";
$u_check = "";

//registration form
$first_name =  mysql_real_escape_string(strip_tags(stripslashes(@$_POST['first_name'])));
$gender =  mysql_real_escape_string(strip_tags(stripslashes(@$_POST['gender'])));
$age =  mysql_real_escape_string(strip_tags(stripslashes(@$_POST['age'])));
$username = mysql_real_escape_string(strip_tags(stripslashes(@$_POST['username'])));
$password = mysql_real_escape_string(strip_tags(stripslashes(@$_POST['password'])));
$password2 = mysql_real_escape_string(strip_tags(stripslashes(@$_POST['password2'])));
$email = mysql_real_escape_string(strip_tags(stripslashes(@$_POST['email'])));
$email2 = mysql_real_escape_string(strip_tags(stripslashes(@$_POST['email2'])));
$d = date("Y-m-d"); // Year - Month - Day

if ($reg) {
if ($email==$email2) {
//Check if user already exists
$u_check = mysql_query("SELECT `username` FROM `users` WHERE `username`='$username'") or die("MySQL ERROR: ".mysql_error());
//Count the amount of rows where username = $username
$check = mysql_num_rows($u_check);
if ($check == 0) {
//Check all of the fields have been filled in
if ($first_name&&&gender&&age&&$username&&$password&&$password2&&$email&&$email2) {
//Check passwords match
if ($password == $password2) {
//check username characters
if (!ctype_alnum($username)){
  echo $characters_error;
}
else {
//check max length un fn ln
if (strlen($username)>25||strlen($first_name)>25) {
  echo $max_length_error;
}
else
{
//Check max length pw
if (strlen($password)>30||strlen($password)<8) {
  echo $max_length_password_error;
}
else
{
//encrypt
$password = md5($password);
$password2 = md5($password);
$query = mysql_query("INSERT INTO users VALUES ('','$username','$password','$email','$date','$first_name','$age','$gender','','profile_picture_here','banner_picture_here','','variables_next','0','','0','0','0','0','0','0')") or die("MySQL ERROR: ".mysql_error());
die($signedup);
}
}
}
}
else {
echo password_error;
}
}
else
{
echo field_error;
}
}
else
{
echo username_error;
}
}
else
{
echo email_error;
}
}
?>

1 个答案:

答案 0 :(得分:0)

你在第46行写了一个拼写错误'&amp;&amp;&amp;&amp;'而不是'&amp;&amp;'它应该工作。

if ($first_name&&&gender&&age&&$username&&$password&&$password2&&$email&&$email2) {

应该是

if ($first_name&&$gender&&$age&&$username&&$password&&$password2&&$email&&$email2) {

我想。

问候乔