2

我制作了一个 register.php 文件来注册我目前正在构建的网站。我正在运行 XAMPP 来托管我的网站并在通过付费主机上传之前对其进行测试。在一些视频和在线论坛的帮助下制作了 php 文件后,我在谷歌浏览器中打开了它并填写了我创建的注册表单。但是在按下“提交”时出现以下错误,而不是将用户信息成功写入 mysql 数据库。

已弃用:函数 eregi_replace() 在第 53 行的 C:\xampp\htdocs\register.php 中已弃用

警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 56 行的 C:\xampp\htdocs\register.php 中给出

已弃用:函数 eregi_replace() 在第 97 行的 C:\xampp\htdocs\register.php 中已弃用

已弃用:函数 eregi_replace() 在第 98 行的 C:\xampp\htdocs\register.php 中已弃用

已弃用:函数 eregi_replace() 在第 99 行的 C:\xampp\htdocs\register.php 中已弃用

已弃用:函数 eregi_replace() 在第 100 行的 C:\xampp\htdocs\register.php 中已弃用

我知道与eregi_replace()函数相关的错误的原因是因为 php 语言不再支持/使用它。我也知道有一个替代方案,preg_replace()但是问题在于,作为 php 领域的新手,我无法提出解决方案。我每天都在学习更多,但我需要快速完成此页面以继续我的网站和学校我没有时间尝试这么多多个代码块来提出解决方案。我道歉; 我需要一点勺子喂食。:/ 如果您能接受我的代码并告诉我如何修复上面列出的错误,或者甚至更好地使用代码的固定副本做出响应,将不胜感激!感谢您的宝贵时间,我再次为我缺乏知识而道歉。

注册.php:

    <?php
//User check log
//include_once("Scripts/checkuserlog.php");
?>

<?php
// let's initialize vars to be printed to page in the HTML section so our script does not return errors 
// they must be initialized in some server environments
$errorMsg = "";
$firstname = "";
$lastname = "";
$email1 = "";
$email2 = "";
$pass1 = "";
$pass2 = "";

// This code runs only if the form submit button is pressed
if (isset ($_POST['firstname'])){
    
    /* Example of cleaning variables in a loop
    $vars = "";
    foreach ($_POST as $key => $value) {
       $value = stripslashes($value);
       $vars .= "$key = $value<br />";
    }
    print "$vars";
    exit();
    */
     $firstname = $_POST['firstname'];
     $lastname = $_POST['lastname'];
     $email1 = $_POST['email1'];
     $email2 = $_POST['email2'];
     $pass1 = $_POST['pass1'];
     $pass2 = $_POST['pass2'];

     $firstname = stripslashes($firstname);
     $lastname = stripslashes($lastname);
     $email1 = stripslashes($email1); 
     $pass1 = stripslashes($pass1); 
     $email2 = stripslashes($email2);
     $pass2 = stripslashes($pass2); 

     $firstname = strip_tags($firstname);
     $lastname = strip_tags($lastname);
     $email1 = strip_tags($email1);
     $pass1 = strip_tags($pass1);
     $email2 = strip_tags($email2);
     $pass2 = strip_tags($pass2);

     // Connect to database
     include_once "/Scripts/connect_to_mysql.php";
     $emailCHecker = mysql_real_escape_string($email1);
     $emailCHecker = eregi_replace("`", "", $emailCHecker);
     // Database duplicate e-mail check setup for use below in the error handling if else conditionals
     $sql_email_check = mysql_query("SELECT email FROM members WHERE email='$emailCHecker'");
     $email_check = mysql_num_rows($sql_email_check); 

     // Error handling for missing data
     if ((!$firstname) || (!$lastname) || (!$email1) || (!$email2) || (!$pass1) || (!$pass2)) { 

     $errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
  
     if(!$firstname){ 
       $errorMsg .= ' * First Name<br />';
     } 
     if(!$lastname){ 
       $errorMsg .= ' * Last Name<br />';
     } 
     if(!$email1){ 
       $errorMsg .= ' * Email Address<br />';      
     }
     if(!$email2){ 
       $errorMsg .= ' * Confirm Email Address<br />';        
     }  
     if(!$pass1){ 
       $errorMsg .= ' * Login Password<br />';      
     }
     if(!$pass2){ 
       $errorMsg .= ' * Confirm Login Password<br />';        
     }  
    
     } else if ($email1 != $email2) {
              $errorMsg = 'ERROR: Your Email fields below do not match<br />';
     } else if ($pass1 != $pass2) {
              $errorMsg = 'ERROR: Your Password fields below do not match<br />';
     } else if ($email_check > 0) { 
              $errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our database. Please use another.<br />"; 
       
     } else { // Error handling is ended, process the data and add member to database
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
     $firstname = mysql_real_escape_string($firstname);
     $lastname = mysql_real_escape_string($lastname);
     $email1 = mysql_real_escape_string($email1);
     $pass1 = mysql_real_escape_string($pass1);
     
     $firstname = eregi_replace("`", "", $firstname);
     $lastname = eregi_replace("`", "", $lastname);
     $email1 = eregi_replace("`", "", $email1);
     $pass1 = eregi_replace("`", "", $pass1);
     
     // Add MD5 Hash to the password variable
     $db_password = md5($pass1); 

     // Add user info into the database table for the main site table(audiopeeps.com)
     $sql = mysql_query("INSERT INTO members (firstname, lastname, email, password, sign_up_date) 
     VALUES('$firstname','$lastname','$email1','$db_password', now())")  
     or die (mysql_error());
 
     $id = mysql_insert_id();
     
     // Create directory(folder) to hold each user's files(pics, MP3s, etc.)        
     mkdir("members/$id", 0755);    

    //!!!!!!!!!!!!!!!!!!!!!!!!!    Email User the activation link    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    $to = "$email1";
                                         
    $from = "admin@Connect.CloudNine.com";
    $subject = "Complete your registration at Cloud Nine";
    //Begin HTML Email Message
    $message = "Hi $firstname,

   Complete this step to activate your login identity at [ yourdomain ].

   Click the line below to activate when ready.

   localhost/activation.php?id=$id&sequence=$db_password
   If the URL above is not an active link, please copy and paste it into your browser address bar

   Login after successful activation using your:  
   E-mail Address: $email1 
   Password: $pass1

   See you on the site!
   ";
   //end of message
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text\r\n";

    mail($to, $subject, $message, $headers);
    
   $msgToUser = "<h2>One Last Step - Activate through Email</h2><h4>OK $firstname, one last step to verify your email identity:</h4><br />
   In a moment you will be sent an Activation link to your email address.<br /><br />
   <br />
   <strong><font color=\"#990000\">VERY IMPORTANT:</font></strong> 
   If you check your email with your host providers default email application, there may be issues with seeing the email contents.  If this happens to you and you cannot read the message to activate, download the file and open using a text editor.<br /><br />
   ";


   include_once 'msgToUser.php'; 

   exit();

   } // Close else after duplication checks

} else { // if the form is not posted with variables, place default empty variables
      
      $errorMsg = "Fields marked with an [ * ] are required";
      $firstname = "";
      $lastname = "";
      $email1 = "";
      $email2 = "";
      $pass1 = "";
      $pass2 = "";
}

?>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome To Cloud Nine</title>
<link href="CSS/register.css" rel="stylesheet" type="text/css">
<link href="CSS/css_boxes_register.css" rel="stylesheet" type="text/css">
<link href="CSS/reg_table_register.css" rel="stylesheet" type="text/css">

</head>

<body>
    <!--Floating Dock-->
    <div id="floating_dock">
    <a href="html_index.html" id="logo"><img src="Images/cloudnine_logo.png" width="220px"></a>
    <img src="Images/button.png" width="75" height="50" id="button"></div>
    <!--Floating Dock End-->
    
    <!--Content Wrap-->
<div id="container_alt">

<form action="register.php" method="post" enctype="multipart/form-data" class="box">
<h3>Account Registration</h3>
<p>&nbsp;</p>
<p>

<table width="447" border="0" align="center" cellpadding="5" cellspacing="1">
  <tr>
    <td width="435" align="center" valign="middle"><?php print "$errorMsg"; ?></td>
  </tr>
  <tr>
    <td align="center">First Name</td>
  </tr>
  <tr>
    <td align="center"><input name="firstname" type="text" id="firstname" value="<?php print "$firstname";?>" size="35" maxlength="35"></td>
  </tr>
  <tr>
    <td align="center">Last Name</td>
  </tr>
  <tr>
    <td align="center"><input name="lastname" type="text" id="lastname" value="<?php print "$lastname";?>" size="35" maxlength="35"></td>
  </tr>
  <tr>
    <td align="center">Password</td>
  </tr>
  <tr>
    <td align="center"><input name="pass1" type="text" id="pass1" value="<?php print "$pass1";?>" size="35" maxlength="35"></td>
  </tr>
  <tr>
    <td align="center">Confirm Password</td>
  </tr>
  <tr>
    <td align="center"><input name="pass2" type="text" id="pass2" value="<?php print "$pass2";?>" size="35" maxlength="35"></td>
  </tr>
  <tr>
    <td align="center">Email</td>
  </tr>
  <tr>
    <td align="center"><input name="email1" type="text" id="email1" value="<?php print "$email1";?>" size="35" maxlength="35"></td>
  </tr>
  <tr>
    <td align="center">Confirm Email</td>
  </tr>
  <tr>
    <td align="center"><input name="email2" type="text" id="email2" value="<?php print "$email2";?>" size="35" maxlength="35"></td>
  </tr>
  <tr>
    <td align="center"><input type="submit" name="submit" value="Submit Form"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</p>
</form>

</div>
     


</body>

</html>
4

1 回答 1

0

如果您不需要它,则无需执行正则表达式。改变

eregi_replace("`", "", $emailCHecker);

str_replace("`", "", $emailCHecker);

不要使用 mysql_* 函数,因为它们已被弃用。使用 mysqli 或 PDO 或任何你喜欢的风格,但不要再使用 mysql_* 了!

不鼓励使用此扩展程序。相反,应该使用 MySQLi 或 PDO_MySQL 扩展。另请参阅 MySQL:选择 API 指南和相关的常见问题解答以获取更多信息。

于 2012-10-12T06:12:33.537 回答