0

我的错误朋友...下面是我正在编写一个 jquery php bases 注册表单代码的完整代码。似乎代码工作正常,但我无法在 mysql 数据库中输入数据。请让我知道我哪里出错了。下面是表格:

        <!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" media="all" href="home_style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>



<script>
   $(document).ready(function(){
      $("#ajax-contact-form").submit(function(){
      var str = $(this).serialize();
          $.ajax(
         {
         type: "POST",
        url:"contact.php",
        data: str,
        success:function(result)
                {
                $("#div1").html(result);
                }
         });
     return false;
     });
 });
</script>


</head>
<body>

<div id="contact_form">  
<form id="ajax-contact-form" name="contact" action=""> 
<fieldset>
    <div class="field_container">First Name:</label>
<input type="text" name="cust_firstname" id="firstname"  maxlength="50" onblur="fnamevalidation()" style="width: 250px; height: 30px"; />



<div class="field_container">Last Name:</label>
<input type="text" name="cust_lastname" id="lastname" maxlength="50" onblur="lnamevalidation()" style="width: 250px; height: 30px"; />


<div class="sex_check" >
<input type="radio" name="cust_sex" type="radio" value="M" /> Male
<input type="radio" name="cust_sex" type="radio" value="F" /> Female


<hr class="line_break">

<div class="field_container">Email:</label>
<input type="text" name="cust_email" id="email"  maxlength="100" onblur="emvalidation()" style="width: 250px; height: 30px"; />



<div class="field_container">Password:</label>
<input type='password' name='cust_password' id='password'  maxlength="12" onblur="pwordvalidation()" style="width: 250px; height: 30px"; />



<div class="field_container">Confirm Password:</label>
<input type='password' name='cust_password2' id='confirmpassword'  maxlength="12" onblur="cpwordvalidation()" style="width: 250px; height: 30px"; />




<INPUT class="button" type="submit" name="submit" value="Register">

 </fieldset>  
</form>
</div> 

<div id="div1">
</div> 


</body>
</html>

和contact.php是

<?php
ob_start();

    session_start();

    require_once("config.php");




    $cust_firstname = stripslashes($_POST['cust_firstname']);

        $cust_lastname=stripslashes($_POST['cust_lastname']);

        $cust_sex=$_POST['cust_sex'];

    $cust_email=stripslashes($_POST['cust_email']);

    $cust_password=stripslashes($_POST['cust_password']);

    $cust_password2=stripslashes($_POST['cust_password2']);






// Get values from form



    if(isset($_POST['Submit'])) 

{

    // Insert data into mysql 

        $res = mysql_query("SELECT * FROM register WHERE cust_email = '$cust_email'");

            if (mysql_num_rows($res)>0)

                    {

                    echo 'That email is already registered';

                    exit;

                    }

            mysql_query("INSERT INTO register (`cust_firstname`,`cust_lastname`, `cust_sex`, `cust_email`, `cust_password`) 

            VALUES

            ('$cust_firstname', '$cust_lastname', '$cust_sex', '$cust_email', '$cust_password')");

            $_SESSION['valid_user'] = $cust_email;


    }




    echo $cust_firstname;

    echo $cust_lastname;

    echo $cust_sex;

    echo $cust_email;

    echo $cust_password;

    echo $cust_password2;



    ?>
4

1 回答 1

0

您应该删除 PHP 文件中的if(isset($_POST['Submit'])). 第一,您的按钮名称是“提交”(带有小写的 s),第二,该变量不会被发送,因此它永远不会为真。然后它应该工作。但我建议查看您的 HTML 标记。这是完全无效的。

于 2013-08-10T10:32:17.893 回答