몇 달 전에 프로젝트 등록 기능을 만들었습니다. 어제까지 완벽하게 작동 했었습니다. 몇 가지 좋은 점을 수정하지 않았으므로 어떻게 될지 잘 모르겠습니다. 주, 내가 체크했던 지난 번에 일하고 있었던 시간. 나는 그것을 직접 디버깅하려고 시도했지만, 그걸 잘못 해석 할 수는 없으며, 무엇을해야할지 모르겠습니다!등록 기능
코드가 여러 페이지에 걸쳐 분할 있지만, 본질적으로, 여기에 무슨 일이 일어나고 있는지의있다 : 건설
<?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>
HTML
<?php
/*
ini_set('display_errors', 1);
error_reporting(E_ALL);
*/
function clean_string($string) {
$string = trim($string);
$string = utf8_decode($string);
$string = str_replace("#", "#", $string); $string = str_replace("%", "%", $string);
if (mysql_real_escape_string($string)) {
$string = mysql_real_escape_string($string);
}
if (get_magic_quotes_gpc()) {
$string = stripslashes($string);
}
return htmlentities($string);
}
?>
후에 등록을 Clean.php 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 : 액세스가 '사용자'@ 'localhost를'(암호를 사용하여 : NO) 거부에 \ 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 깨끗한 후에 11 행에 있습니다. 정의되지 않은 색인 : \ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new의 이름 \ register-controller.php on line 100 경고 : mysql_real_escape_string() : 사용자 ''@ 'localhost'에 대한 액세스가 거부되었습니다 (암호를 사용하여 : NO) \ I에서 CS-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 on line 11 알림 : 정의되지 않은 색인 : 성은 \ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ register에 있습니다. -controller.php on line 101 경고 : mysql_real_escape_string() : \ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new에서 사용자 ''@ 'localhost'(암호 사용 : NO)에 대한 액세스가 거부되었습니다. \ clean.php on line 11 경고 : mysql_real_escape_string() : 11 행의 \ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php에 서버에 대한 링크를 만들 수 없습니다 경고 : mysql_real_escape_string() : \ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php의 11 번 줄에있는 사용자 '' ''localhost '(암호 사용 : NO)에 대한 액세스가 거부되었습니다. 경고 : mysql_real_escape_string() : 서버가 \ ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php 11 행에 설치되지 않았습니다 경고 : mysql_real_escape_string() : 사용자 ''@ 'localhost'에 대한 액세스가 거부되었습니다 (패스워드 사용 : NO) 11 행 : \ ICS-FILESHARE \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ clean.php 경고 : mysql_real_escape_string() : 서버에 대한 링크를 \ 11 행의 경고 : mysql_real_escape_string() : 사용자 '@'localhost '에 대한 액세스가 거부되었습니다 (암호 사용 : NO) \에있는 ICS-FILESHARE \ WWW \ newmedia.leeds.ac.uk \ ug10 \ cs10aer \ screening_new \ 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 on line 11
하지만 데이터베이스 conn을 확인했습니다. 모든 정보는 정상적으로 보입니다. 로그인 및 추가, 삭제 및 수정과 같은 웹 사이트의 다른 기능은 모두 완벽하게 작동하며 동일한 데이터베이스 연결 스크립트를 사용하므로 갑자기 깨진이 등록 기능입니다. 이해할 수없는 이유들.
디버그하기가 너무 어려워서 mysql 또는 사용중인 PHP 버전을 다시 설치하십시오. – samayo
불행히도 저는 대학의 서버에서 작업 중이며 이와 같은 시설에 액세스 할 수 없습니다. 내가 할 수있는 것은 코드 뿐이며 오류보고를 사용하여 오류를 확인합니다. –
+1 문자열 청소! – span