0

整晚都在看这个,我放弃了......代码直接从 $result 到最后一行,所以有些东西失败了

错误日志中没有任何内容 死时不显示错误消息。直接进入 reg_fail.html

<?php

$host = '.......'; // Host Name
$sql_username = '......'; // Sql Username
$sql_password = '.......'; // Password
$db_name = '..............'; //Database Name


$con = mysql_connect($host, $sql_username, $sql_password)or die('Error connecting to server');
mysql_select_db( $db_name)or die('Error connecting to database');


$firstName = mysql_real_escape_string($_POST['regFirstName']);
$lastName = mysql_real_escape_string($_POST['regLastName']);
$username = mysql_real_escape_string($_POST['regUser']);
$email = mysql_real_escape_string($_POST['regEmail']);

$password = mysql_real_escape_string($_POST['regPassword']);
$password = md5($password);

$query = "SELECT * FROM user WHERE username = '$username'";
$result = mysql_query($query) or die($query."<br/><br/>".mysql_error());


if($result){

$count = mysql_num_rows($result);

if($count == 0){

    try{        



    $query = "INSERT INTO user (username, password, first_name, last_name, email)
                                 VALUES ('$username', '$password', '$firstName', '$lastName', '$email')";


    mysql_query($query , $con); 

    header('location: registration_success.html');  

    }catch(Exception $e){
    header('location: registration_fail_userTaken.html');
    }

}

header('location: registration_fail_userTaken.html');

}

header('location: registration_fail.html'); 




?>
4

3 回答 3

1

在每个header( ) 之后使用exit( ) 。或使用.if(){}else{}

于 2013-05-17T06:44:00.037 回答
0

您始终发送最后一个标头,因此即使您重定向到某些内容,最后一个标头也将始终重定向到“失败”。

所以只需将其包装成else.

于 2013-05-17T06:36:50.490 回答
0

改变这个

mysql_select_db( $db_name)or die('Error connecting to database');

mysql_select_db( $db_name ,$con)or die('Error connecting to database');
于 2013-05-17T06:40:20.277 回答