PHP代码中的500错误

PHP代码中的500错误,php,Php,我正在尝试为我正在工作的网站创建一个登录页面,我可以访问服务器 我可以加载一些100%可用的页面,但当我向站点添加成员时,会显示一条错误消息: 错误500 sharedweb.unisite.ac.uk页面不工作。sharedweb.unisite.ac.uk当前无法处理此请求 我不知道为什么。导致此错误的脚本是: <?php // include function files for this application require_once('bookmark_fns.php

我正在尝试为我正在工作的网站创建一个登录页面,我可以访问服务器

我可以加载一些100%可用的页面,但当我向站点添加成员时,会显示一条错误消息:

错误500

sharedweb.unisite.ac.uk页面不工作。sharedweb.unisite.ac.uk当前无法处理此请求

我不知道为什么。导致此错误的脚本是:

<?php

  // include function files for this application
  require_once('bookmark_fns.php');

  //create short variable names
  $email=$_POST['email'];
  $username=$_POST['username'];
  $passwd=$_POST['passwd'];
  $passwd2=$_POST['passwd2'];
  // start session which may be needed later
  // start it now because it must go before headers
  session_start();
  try   {
    // check forms filled in
    if (!filled_out($_POST)) {
      throw new Exception('You have not filled the form out correctly. Please go back and try again.');
    }

    // email address not valid
    if (!valid_email($email)) {
      throw new Exception('That is not a valid email address.  Please go back and try again.');
    }

    // passwords not the same
    if ($passwd != $passwd2) {
      throw new Exception('The passwords you entered do not match. Please go back and try again.');
    }

    // check password length is ok
    // ok if username truncates, but passwords will get
    // munged if they are too long.
    if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z]{6,12}$/)', $passwd)) {
        throw new Exception('Your password must be between 6 and 12 characters inclusive. Please go back and try again.');
    }

    // attempt to register
    // this function can also throw an exception
    register($username, $email, $passwd);
    // register session variable
    $_SESSION['valid_user'] = $username;

    // provide link to members page
    do_html_header('Registration successful');
    echo "Welcome " $_POST["username"];
    echo 'Your registration was successful.  Go to the members page to start setting up your bookmarks!';
    do_html_url('member.php', 'Go to members page');

   // end page
   do_html_footer();
  }
  catch (Exception $e) {
     do_html_header('Warning:');
     echo $e->getMessage();
     do_html_footer();
     exit;
  }
?>


如何修复此问题?

您的代码中有两个语法错误:

首先,您需要使用
将字符串与变量连接起来:

echo "Welcome " . $_POST["username"];
第二,这里有一个额外的结束括号:

if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z]{6,12}$/)', $passwd)) {
    throw new Exception('Your password must be between 6 and 12 characters inclusive. Please go back and try again.');
}
拆下额外的支架:

if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z]{8,12}$/', $passwd)) {
    throw new Exception('Your password must be between 6 and 12 characters inclusive. Please go back and try again.');
}

关于这个错误:

已弃用:函数ereg()已弃用

PHP手册:

在PHP5.3.0中被弃用,在PHP7.0.0中被删除

查看此帖子:


提示:您应该将此代码添加到PHP文件的顶部,以帮助您查找错误

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

set error reporting on这有一个语法错误,
echo“Welcome”$\u POST[“username”]没有连接,也不知道会话是否已启动。@JainilNagar我已经完成了,但没有显示任何内容,只有
错误500
问题您不应该打印从客户端收到的值(通过此处的$\u POST)。首先使用一个好的代码编辑器来清理它,这样就完全避免了这个问题,更不用说错误检查了。谢谢你的帮助!我现在设法显示了一个页面。然而,现在,随着错误报告功能的开启,第8行的电子邮件、第9行的用户名、第10行的密码和第11行的密码都有了
未定义的索引,第11行的函数ereg()已被弃用15@johnsmith这意味着表单有问题,没有提交值,也许还可以发布您的表单代码?我返回并重新提交表单,在第15行和第34行分别有
弃用的
函数ereg()和
警告:preg_match():Unknown modifier')函数,我收到
错误500
消息again@johnsmith我已经更新了帖子以修复
preg\u match()
error@johnsmith不客气!如果这对您有帮助,您可以点击upvote/downvote按钮下方的勾号来接受此帖子,谢谢:)