duanjiao4763 2016-02-05 21:20 采纳率: 0%
浏览 273
已采纳

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

I have created a user register page, with a HTML form. I have just finished the PHP file to submit the data to a MySQL database.

I have checked that phpMyAdmin is connected to the database and working.

As far as I can see, the MySQL queries and the rest of the PHP code all seems fine, however I am getting an internal error on the page with the PHP code. I have used the include function to include the PHP file on the HTML file, and both the HTML register page and the PHP file return the following error on Chrome:

"The website encountered an error while retrieving [WEB ADDRESS]. It may be down for maintenance or configured incorrectly."

I should also note that it is only this page that is doing it, other pages on the website work fine, so it is defiantly this PHP file. I would paste the code but it's pretty long. I've never gotten a plain 500 error with a PHP file before, I have made similar sign up forms and codes before and never had this problem.

Any help would be much appreciated.

Code

<?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条回答 默认 最新

  • drccfl9407 2016-02-05 22:01
    关注

    You just have a typo on line 46 you wrote '&&&' instead of '&&' it should work then.

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

    should be

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

    I think.

    Greetings Joe

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化