gpt4 book ai didi

php - 将 'eregi_replace' 函数转换为 'preg_replace' 和 'mysql_num_rows' 参数修复

转载 作者:行者123 更新时间:2023-11-28 03:38:17 25 4
gpt4 key购买 nike

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

Deprecated: Function eregi_replace() is deprecated in C:\xampp\htdocs\register.php on line 53

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\register.php on line 56

Deprecated: Function eregi_replace() is deprecated in C:\xampp\htdocs\register.php on line 97

Deprecated: Function eregi_replace() is deprecated in C:\xampp\htdocs\register.php on line 98

Deprecated: Function eregi_replace() is deprecated in C:\xampp\htdocs\register.php on line 99

Deprecated: Function eregi_replace() is deprecated in C:\xampp\htdocs\register.php on line 100

我知道与 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>

最佳答案

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

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

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

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

Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

关于php - 将 'eregi_replace' 函数转换为 'preg_replace' 和 'mysql_num_rows' 参数修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12852083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com