【问题标题】:Why am I getting a 500 Internal Error with a PHP file? [closed]为什么 PHP 文件会出现 500 内部错误? [关闭]
【发布时间】:2016-02-05 21:20:47
【问题描述】:

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

我已检查 phpMyAdmin 是否已连接到数据库并正在工作。

据我所知,MySQL 查询和 PHP 代码的其余部分似乎都很好,但是我在 PHP 代码的页面上遇到了内部错误。我已经使用include函数在HTML文件中包含了PHP文件,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;
}
}
?>

【问题讨论】:

标签: php html mysql google-chrome


【解决方案1】:

你只是在第 46 行有一个错字,你写的是 '&&&' 而不是 '&&' 它应该可以工作。

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

应该是

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

我认为。

问候乔

【讨论】:

  • 确定这是一个错误,但不确定这是否会导致 500 错误,是吗?
  • 是的。 500 错误意味着在编译 PHP 代码时会产生错误,并且 &&& 不是有效的 PHP 会产生错误。由于您也忘记了年龄之前的 $ 它应该给您另一个错误,因为未声明年龄,因为您的意思是变量 $age。
  • @putvande 正是我的想法,但我解决了这个问题,错误已经消失,所以我猜它确实如此。谢谢你们两个:)
  • 如果你在本地运行的服务器上工作,你应该在你的 php.ini 文件中激活 PHP 错误,这样你就会看到你的错误是什么,而不是 500 错误和需要锁定 php错误日志文件。
  • @JoePi 我也用 $gender 变量做到了这一点。修复了它们,这是因为我正在使用一个新的文本编辑器,而这个没有突出显示变量,所以当我浏览 & 看起来像 $.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-16
  • 2023-04-01
  • 2021-08-10
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
相关资源
最近更新 更多