注册功能(Registration function)

编程入门 行业动态 更新时间:2024-10-23 16:17:07
注册功能(Registration function)

几个月前我为我的项目建立了一个注册功能,它一直工作到昨天,我不太确定发生了什么,因为我好几周都没有用它改变任何东西,那时候我上次检查时工作正常。 我自己试图调试它,但我发现它没有任何问题,我不知道还能做什么!

代码分为多个页面,但基本上,这是正在发生的事情:

HTML构造

<?php require_once("clean.php"); ?> <ul class="nav pull-right"><?php if (isset($_SESSION['logged'])) {?> <li><a href="profile.php">Profile</a></li> <li><a href="logout.php">Logout</a></li><?php } else {?> <li><a href="#register" class="account-register" data-toggle="modal" title="Register a new Screening account">Register</a></li> <li><a href="#login" class="account-login" data-toggle="modal" title="Login to your Screening profile">Login</a></li><?php }?> </ul> <div id="register" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="registerLabel" aria-hidden="true"> <?php require_once("register-controller.php"); ?> <!-- reCAPTCHA jQuery --> <script type="text/javascript"> var RecaptchaOptions = { theme : 'white' }; </script> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="registerLabel" class="modal-title">Register a new Screening account</h3> </div> <form name="register" action="" method='POST' enctype="multipart/form-data"> <div class="modal-body"> <?php echo $register_bad_message; ?> <?php echo $register_good_message; ?> <input class="input-block-level" type="text" name="firstname" placeholder="First Name"> <input class="input-block-level" type="text" name="lastname" placeholder="Last Name"> <input class="input-block-level" type="email" name="email" placeholder="Email"> <input type="file" class="profile-picture-upload" name="profile-image" alt="profile-image"> <input class="input-block-level" type="password" name="password" placeholder="Password"> <input class="input-block-level" type="password" name="confirm-password" class="span3" placeholder="Confirm Password"> <?php include ("recaptcha_form.php") ?> </div> <div class="modal-footer"> <button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Close</button> <button type="submit" class="btn btn-success" name="submit" value="Sign up!">Sign up!</button> </div> </form> </div>

Clean.php

<?php /* ini_set('display_errors', 1); error_reporting(E_ALL); */ function clean_string($string) { $string = trim($string); $string = utf8_decode($string); $string = str_replace("#", "&#35", $string); $string = str_replace("%", "&#37", $string); if (mysql_real_escape_string($string)) { $string = mysql_real_escape_string($string); } if (get_magic_quotes_gpc()) { $string = stripslashes($string); } return htmlentities($string); } ?>

寄存器Controller.php这样

<?php /* ini_set('display_errors', 1); error_reporting(E_ALL); */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); if( $this->image_type == IMAGETYPE_GIF || $this->image_type == IMAGETYPE_PNG ) { $current_transparent = imagecolortransparent($this->image); if($current_transparent != -1) { $transparent_color = imagecolorsforindex($this->image, $current_transparent); $current_transparent = imagecolorallocate($new_image, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']); imagefill($new_image, 0, 0, $current_transparent); imagecolortransparent($new_image, $current_transparent); } elseif( $this->image_type == IMAGETYPE_PNG) { imagealphablending($new_image, false); $color = imagecolorallocatealpha($new_image, 0, 0, 0, 127); imagefill($new_image, 0, 0, $color); imagesavealpha($new_image, true); } } imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } //Clean echo "before clean"; $submit = clean_string($_POST['submit']); echo "after clean"; if ($submit == 'Sign up!') { $first_name = clean_string($_POST['first-name']); $last_name = clean_string($_POST['last-name']); $email = clean_string($_POST['email']); $password = clean_string($_POST['password']); $confirm_password = clean_string($_POST['confirm-password']); //Output variables $register_bad_message = ''; $register_good_message = ''; require_once($_SERVER['DOCUMENT_ROOT'] . '/recaptcha/recaptchalib.php'); $privatekey = "6Ldbd8ASAAAAAFz8VT29H5w4WLNjsbI-mFY2QkaC"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $errMessage = $resp->error; $register_bad_message = '<div class="alert alert-error">The reCAPTCHA you entered wasn\'t correct. Please try again.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } else { if ($first_name&&$last_name&&$email&&$password&&$confirm_password) { if ($password == $confirm_password) { if (strlen($password) > 25 || strlen($password) < 6) { $register_bad_message = '<div class="alert alert-error">Please enter a password between 6 and 25 characters.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } else { require_once("db_connect.php"); if($db_server) { $first_name = clean_string($first_name); $last_name = clean_string($last_name); $email = clean_string($email); $password = clean_string($password); echo "1"; mysql_select_db($db_database); $taken = mysql_query("SELECT email FROM users WHERE email='$email'"); $count = mysql_num_rows($taken); if ($count > 0) { $register_bad_message = '<div class="alert alert-error">The email you have entered is already associated with a Screening account. Please choose another.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } else { if ($_FILES) { //Put file properties into variables $file_name = $_FILES['profile-image']['name']; $file_size = $_FILES['profile-image']['size']; $file_tmp_name = $_FILES['profile-image']['tmp_name']; //Determine filetype switch ($_FILES['profile-image']['type']) { case 'image/jpeg': $ext = "jpg"; break; case 'image/png': $ext = "png"; break; default: $ext = ''; break; } if ($ext) { //Check filesize if ($file_size < 5242880) { //Process file - resize, clean up filename and move to safe location $image = new SimpleImage(); $image->load($file_tmp_name); $image->resizeToWidth(250); $image->save($file_tmp_name); $n = "$file_name"; $n = ereg_replace("[^A-Za-z0-9.]", "", $n); $n = strtolower($n); $n = "avatars/$n"; move_uploaded_file($file_tmp_name, $n); } else { $register_bad_message = '<div class="alert alert-error">Please ensure your chosen file is less than 5MB.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } else { $register_bad_message = '<div class="alert alert-error">Please ensure your image is of filetype .jpg or.png.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } $password = md5($password); $query = "INSERT INTO users (first_name, last_name, email, password, image) VALUES ('$first_name', '$last_name', '$email', '$password', '$n')"; mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query); $register_good_message = '<div class="alert alert-success">Registration successful! <br /> <a href='#login' data-toggle='modal' title='Login to your Screening profile'>Login now</a></div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } else { $register_bad_message = '<div class="alert alert-error">Error: could not connect to the database.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } require_once("db_close.php"); } } else { $register_bad_message = '<div class="alert alert-error">Passwords failed to match. Please try again.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } else { $register_bad_message = '<div class="alert alert-error">Please fill in all fields before continuing.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } } ?>

如果我打开错误报告,我收到的消息是:

在清理之前警告:mysql_real_escape_string():在\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中拒绝用户''@ localhost'(使用密码:NO)第11行警告:mysql_real_escape_string():无法在第11行的\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中建立到服务器的链接通知:未定义index:第100行\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ register-controller.php第一行警告:mysql_real_escape_string():用户''@ localhost拒绝访问第11行\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中的'(使用密码:否)警告:mysql_real_escape_string():无法建立指向服务器的链接在第11行的\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中注意:未定义的索引:\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac中的姓氏。英国\ ug10 \ cs10aer \ screening_new \ REGIST 第101行的er-controller.php警告:mysql_real_escape_string():在\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \中拒绝用户''@ localhost'(使用密码:NO)第11行的screening_new \ clean.php警告:mysql_real_escape_string():无法在\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中建立到服务器的链接11警告:mysql_real_escape_string():在\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中,用户''@ localhost'(使用密码:NO)拒绝访问11警告:mysql_real_escape_string():无法在第11行的\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中建立到服务器的链接警告:mysql_real_escape_string():在第11行的\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中,用户''@ localhost'(使用密码:NO)拒绝访问警告:mysql_real_escape_string():指向服务器的链接 ld不能在第11行的\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中建立警告:mysql_real_escape_string():用户''@ localhost'拒绝访问(使用密码:NO)在第11行的\ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php中警告:mysql_real_escape_string():无法在\ ICS中建立到服务器的链接第11行的-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php

但我检查了我的数据库连接,一切似乎都没问题 - 网站上的其他功能,如登录和添加,删除和修改数据库详细信息都完美无缺,并且他们使用相同的数据库连接脚本,所以这只是注册因为我无法理解的原因而突然破碎的功能。

I built a registration feature for my project a few months ago, and it's been working perfectly until yesterday, and I'm not quite sure what's gone on, as I haven't changed anything with it for a good few weeks, at which time it was working last time I checked. I've attempted to debug it myself, but I can't find anything wrong with it, and I'm not sure what else to do!

The code is split across multiple pages, but essentially, here's what's going on:

HTML Construction

<?php require_once("clean.php"); ?> <ul class="nav pull-right"><?php if (isset($_SESSION['logged'])) {?> <li><a href="profile.php">Profile</a></li> <li><a href="logout.php">Logout</a></li><?php } else {?> <li><a href="#register" class="account-register" data-toggle="modal" title="Register a new Screening account">Register</a></li> <li><a href="#login" class="account-login" data-toggle="modal" title="Login to your Screening profile">Login</a></li><?php }?> </ul> <div id="register" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="registerLabel" aria-hidden="true"> <?php require_once("register-controller.php"); ?> <!-- reCAPTCHA jQuery --> <script type="text/javascript"> var RecaptchaOptions = { theme : 'white' }; </script> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="registerLabel" class="modal-title">Register a new Screening account</h3> </div> <form name="register" action="" method='POST' enctype="multipart/form-data"> <div class="modal-body"> <?php echo $register_bad_message; ?> <?php echo $register_good_message; ?> <input class="input-block-level" type="text" name="firstname" placeholder="First Name"> <input class="input-block-level" type="text" name="lastname" placeholder="Last Name"> <input class="input-block-level" type="email" name="email" placeholder="Email"> <input type="file" class="profile-picture-upload" name="profile-image" alt="profile-image"> <input class="input-block-level" type="password" name="password" placeholder="Password"> <input class="input-block-level" type="password" name="confirm-password" class="span3" placeholder="Confirm Password"> <?php include ("recaptcha_form.php") ?> </div> <div class="modal-footer"> <button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Close</button> <button type="submit" class="btn btn-success" name="submit" value="Sign up!">Sign up!</button> </div> </form> </div>

Clean.php

<?php /* ini_set('display_errors', 1); error_reporting(E_ALL); */ function clean_string($string) { $string = trim($string); $string = utf8_decode($string); $string = str_replace("#", "&#35", $string); $string = str_replace("%", "&#37", $string); if (mysql_real_escape_string($string)) { $string = mysql_real_escape_string($string); } if (get_magic_quotes_gpc()) { $string = stripslashes($string); } return htmlentities($string); } ?>

register-controller.php

<?php /* ini_set('display_errors', 1); error_reporting(E_ALL); */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); if( $this->image_type == IMAGETYPE_GIF || $this->image_type == IMAGETYPE_PNG ) { $current_transparent = imagecolortransparent($this->image); if($current_transparent != -1) { $transparent_color = imagecolorsforindex($this->image, $current_transparent); $current_transparent = imagecolorallocate($new_image, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']); imagefill($new_image, 0, 0, $current_transparent); imagecolortransparent($new_image, $current_transparent); } elseif( $this->image_type == IMAGETYPE_PNG) { imagealphablending($new_image, false); $color = imagecolorallocatealpha($new_image, 0, 0, 0, 127); imagefill($new_image, 0, 0, $color); imagesavealpha($new_image, true); } } imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } //Clean echo "before clean"; $submit = clean_string($_POST['submit']); echo "after clean"; if ($submit == 'Sign up!') { $first_name = clean_string($_POST['first-name']); $last_name = clean_string($_POST['last-name']); $email = clean_string($_POST['email']); $password = clean_string($_POST['password']); $confirm_password = clean_string($_POST['confirm-password']); //Output variables $register_bad_message = ''; $register_good_message = ''; require_once($_SERVER['DOCUMENT_ROOT'] . '/recaptcha/recaptchalib.php'); $privatekey = "6Ldbd8ASAAAAAFz8VT29H5w4WLNjsbI-mFY2QkaC"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $errMessage = $resp->error; $register_bad_message = '<div class="alert alert-error">The reCAPTCHA you entered wasn\'t correct. Please try again.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } else { if ($first_name&&$last_name&&$email&&$password&&$confirm_password) { if ($password == $confirm_password) { if (strlen($password) > 25 || strlen($password) < 6) { $register_bad_message = '<div class="alert alert-error">Please enter a password between 6 and 25 characters.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } else { require_once("db_connect.php"); if($db_server) { $first_name = clean_string($first_name); $last_name = clean_string($last_name); $email = clean_string($email); $password = clean_string($password); echo "1"; mysql_select_db($db_database); $taken = mysql_query("SELECT email FROM users WHERE email='$email'"); $count = mysql_num_rows($taken); if ($count > 0) { $register_bad_message = '<div class="alert alert-error">The email you have entered is already associated with a Screening account. Please choose another.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } else { if ($_FILES) { //Put file properties into variables $file_name = $_FILES['profile-image']['name']; $file_size = $_FILES['profile-image']['size']; $file_tmp_name = $_FILES['profile-image']['tmp_name']; //Determine filetype switch ($_FILES['profile-image']['type']) { case 'image/jpeg': $ext = "jpg"; break; case 'image/png': $ext = "png"; break; default: $ext = ''; break; } if ($ext) { //Check filesize if ($file_size < 5242880) { //Process file - resize, clean up filename and move to safe location $image = new SimpleImage(); $image->load($file_tmp_name); $image->resizeToWidth(250); $image->save($file_tmp_name); $n = "$file_name"; $n = ereg_replace("[^A-Za-z0-9.]", "", $n); $n = strtolower($n); $n = "avatars/$n"; move_uploaded_file($file_tmp_name, $n); } else { $register_bad_message = '<div class="alert alert-error">Please ensure your chosen file is less than 5MB.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } else { $register_bad_message = '<div class="alert alert-error">Please ensure your image is of filetype .jpg or.png.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } $password = md5($password); $query = "INSERT INTO users (first_name, last_name, email, password, image) VALUES ('$first_name', '$last_name', '$email', '$password', '$n')"; mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query); $register_good_message = '<div class="alert alert-success">Registration successful! <br /> <a href='#login' data-toggle='modal' title='Login to your Screening profile'>Login now</a></div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } else { $register_bad_message = '<div class="alert alert-error">Error: could not connect to the database.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } require_once("db_close.php"); } } else { $register_bad_message = '<div class="alert alert-error">Passwords failed to match. Please try again.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } else { $register_bad_message = '<div class="alert alert-error">Please fill in all fields before continuing.</div>';?> <script> $('a.account-register').trigger('click'); </script><?php } } } ?>

If I turn error reporting on, the message I get is:

before clean Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 after clean Notice: Undefined index: first-name in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\register-controller.php on line 100 Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Notice: Undefined index: last-name in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\register-controller.php on line 101 Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in \ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11

But I've checked my database connections and everything seems OK - other features on the website, such as logging in and adding, deleting and amending database details are all working perfectly, and they use the same database connection script, so it's just this registration feature which has suddenly broken, for reasons I can't understand.

最满意答案

您必须在调用mysql_real_escape_string之前连接到数据库。 当代码到达此点时,尚未建立连接:

//Clean echo "before clean"; $submit = clean_string($_POST['submit']); echo "after clean";

或者,您可以使用非安全的mysql_escape_string函数。 mysql_real_escape_string需要数据库连接,因为它需要知道连接的字符编码。

You have to connect to the database before calling mysql_real_escape_string. When the code reaches this point the connection has not yet been made:

//Clean echo "before clean"; $submit = clean_string($_POST['submit']); echo "after clean";

Alternatively you can use the not-as-safe mysql_escape_string function. mysql_real_escape_string needs a database connection because it needs knowledge of the connection's characters encoding.

更多推荐

本文发布于:2023-07-24 20:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1250546.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   Registration   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!