0

好的帮助..我的注册页面在本地服务器上工作,但现在说两条mysql行在其在线时无效..为什么它在上线时会改变?粘贴的代码都是相关的。出于某种原因,它不喜欢交易..和电子邮件检查 mysql 位

include 'Connect.php'; //Connects to database
//When form is submit:-
if(isset($_POST['submit']))
{         
                        // On submit, retrieve table values for php.                 
                        $Firstname = mysql_real_escape_string($_POST['firstname']);
                        $Surname = mysql_real_escape_string($_POST['surname']);
                        $Password = mysql_real_escape_string($_POST['password']); 
                        $PasswordCheck = mysql_real_escape_string($_POST['passwordcheck']); 
                        $Email = mysql_real_escape_string($_POST['email']); 
                        $EmailCheck = mysql_real_escape_string($_POST['emailcheck']); 

                    //CHECKS. 
                    //Check username is available by retrieving any same values from the DB table.          
                    $CheckEmailAvailable = mysql_query("SELECT * FROM 'user_details' WHERE Email = '$Email'");
                    echo $CheckEmailAvailable;
                    // $result = mysql_query("SELECT * FROM $tbl WHERE Email='$email' and LoginPassword='$password'");
                    $Results = mysql_fetch_array($CheckEmailAvailable);

                    //If Username field is blank.
                    if($Email == null )
                    {               
                        echo "You must enter an email address.";
                        $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
                        echo "<br/><br/>";
                        echo "<a href='$url'>Click Here To Return</a>";
                        die();                      
                    }

                    //If RESULTS is any value other than NULL, die.
                    if($Results != null )
                    {               
                        echo "Email already taken. Please try another.";
                        $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
                        echo "<br/><br/>";
                        echo "<a href='$url'>Click Here To Return</a>";
                        die();                  
                    }

                    //If Password and PasswordCheck fields in reg do not match, die.
                    if($Password != $PasswordCheck) 
                    {
                        echo "The passwords you have entered do not match. Please try again.";
                        $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
                        echo "<br/><br/>";
                        echo "<a href='$url'>Click Here To Return</a>";
                        die();
                    }

                    //If Password field is NULL (i.e. blank) die.
                    if($Password == Null)
                    {
                        echo "Your password must not be blank.";
                        $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
                        echo "<br/><br/>";
                        echo "<a href='$url'>Click Here To Return</a>";
                        die();
                    }

                    //If Email and EmailCheck are not equal, die.
                    if($Email != $EmailCheck)
                    {                                                                        
                        echo "The email addresses you have entered do not match. Please try again.";
                        $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
                        echo "<br/><br/>";
                        echo "<a href='$url'>Click Here To Return</a>";
                        die();

                    }


                    //ELSE add data to DB.
                    else
                    {
                    //BEGIN TRANS
                    mysql_query("BEGIN TRAN");

                    //TABLE ADD.
                    $sql=mysql_query("INSERT INTO `user_details` (`Firstname`, `Surname`, `Email`, `Password`) VALUES ('$Firstname', '$Surname', '$Email', '$Password')")
                    or mysql_query("ROLLBACK TRAN") . die(mysql_error("Error registering, the database may be down, please try again later."));


                    //COMMIT transaction, to ensure data is added properly.
                    mysql_query("COMMIT TRAN");
                    header( 'Location: RegSucc.php' ) ;
                    }   
                } ?>
              <html> 
            <!--Registration Form-->
            <form name="form1" method="post" style="margin-left: 28%" action="Register.php">
                <table width="100%" border="0" cellpadding="3" cellspacing="1">
                <tr>
                    <td colspan="3"><strong>Register Account</strong></td>
                </tr>
                <tr>
                    <td style="width: 83px">First Name:</td>
                    <td>:</td>
                    <td><input name="firstname" type="text"/></td>
                </tr>
                <tr>
                    <td style="width: 83px">Surname:</td>
                    <td>:</td>
                    <td><input name="surname" type="text"/></td>
                </tr>
                <tr>
                    <td style="width: 83px">Email Address:</td>
                    <td>:</td>
                    <td><input name="email" type="text"/></td>
                </tr>
                <tr>
                    <td style="width: 83px">Email Address Confirmation:</td>
                    <td>:</td>
                    <td><input name="emailcheck" type="text"/></td>
                </tr>
                <tr>
                    <td style="width: 83px">Password:</td>
                    <td>:</td>
                    <td><input name="password" type="password"/></td>
                </tr>
                <tr>
                    <td style="width: 83px">Verify Password:</td>
                    <td>:</td>
                    <td><input name="passwordcheck" type="password"/></td>
                </tr>
                <tr>
                    <td style="width: 83px">&nbsp;</td>
                    <td>&nbsp;</td>
                    <td><input type="submit" name="submit" value="Register"/></td>
                </tr>
                </table>
            </form>
4

3 回答 3

1

查询

SELECT * FROM 'user_details' WHERE Email = '$Email'

是无效的。表示表名时,最好使用反引号,但使用引号是行不通的!

SELECT * FROM `user_details` WHERE Email = '$Email'

在您的本地主机上,它可能被设置为使用引号。但是,这不是“应该”的方式,服务器的安装可能会有所不同。故事的寓意:不要走捷径或使用丑陋的代码。不要忘记反引号表名或列,不要使用 PHP 短标签等。

于 2012-05-17T10:58:51.363 回答
0
$sql=mysql_query("INSERT INTO `user_details` (`Firstname`, `Surname`, `Email`, `Password`) VALUES ('$Firstname', '$Surname', '$Email', '$Password')")

应该

$sql=mysql_query("INSERT INTO user_details (Firstname, Surname, Email, Password) VALUES ('$Firstname', '$Surname', '$Email', '$Password')")

SELECT * FROM 'user_details' WHERE Email = '$Email'

应该

SELECT * FROM user_details WHERE Email = '$Email'

就是这样...

于 2012-05-17T11:06:17.790 回答
0

更改此行

$CheckEmailAvailable = mysql_query("SELECT * FROM 'user_details' WHERE Email = '$Email'");

$CheckEmailAvailable = mysql_query("SELECT * FROM user_details WHERE Email = '".$Email."'");

The problem is that when you moved to another server online (I can guess you were developing on Windows[which is case insensitive in MySQL], and your online server is Linux[case sensitive in MySQL]

If your string contains a variable to be evaluated and parsed, the use of single quotes around that variable name, within the double quote containing that string, is not so reliable most times. The best approach, (from personal experiences) is to do a concatenation.

于 2012-05-17T11:17:29.257 回答