2012-10-12 41 views
2

我已經創建了一個register.php文件來註冊我正在構建的網站。我運行XAMPP來託管我的網站並在我通過付費主機上傳之前對其進行測試。在一些視頻和在線論壇的幫助下製作php文件後,我在google chrome中打開它,並填寫了我創建的註冊表單。但按'提交'時出現以下錯誤,而不是將用戶信息成功寫入mysql數據庫。將'eregi_replace'函數轉換爲'preg_replace'和'mysql_num_rows'參數修復

推薦使用:功能eregi_replace()被棄用在C:\ XAMPP \ htdocs中\ register.php上線53

警告:mysql_num_rows()預計參數1是資源,在布爾C中給出:\ XAMPP \ htdocs中\ register.php在線路56上

已過時:功能eregi_replace()被棄用在C:\ XAMPP \ htdocs中\ register.php線97上

推薦使用:功能eregi_replace(c)中已被棄用:98線上的\ xampp \ htdocs \ register.php

推薦使用:功能eregi_replace()被棄用在C:\ XAMPP \ htdocs中\ register.php上線99

推薦使用:功能eregi_replace()中C被棄用:\ XAMPP \ htdocs中\上線register.php 100

我知道與eregi_replace()函數有關的錯誤原因是因爲它不再被php語言支持/使用。我也知道有一個替代preg_replace()然而,問題在於,作爲php領域的新手,我無法提出解決方案。我每天都在學習更多,但我需要快速完成此頁面,以便繼續使用我的網站和學校,我沒有時間嘗試使用如此多的多個代碼塊來提供解決方案。我道歉;我將需要一個小湯匙餵養。 :/如果你可以拿我的代碼,並告訴我如何解決上面列出的錯誤,甚至更好地回覆代碼的固定副本,將非常感謝!感謝您的時間,並再次爲我缺乏知識而道歉。

register.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 = "[email protected]"; 
    $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> 
+0

http://php.net/manual/en/reference.pcre.pattern.posix.php您的numrows問題是由於查詢失敗和完全沒有錯誤處理 - 永遠不會假設數據庫查詢具有成功了。 –

回答

0

不需要做正則表達式,如果你不需要它。更改

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

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

不要使用mysql_ *功能,因爲它們已被棄用。使用mysqli或PDO或任何你喜歡的口味,但不要再使用mysql_ *了!

不推薦使用此擴展名。應該使用MySQLi或PDO_MySQL 擴展。另請參閱MySQL:選擇API指南和 相關的FAQ以獲取更多信息。