表单数据未插入数据库

时间:2012-07-18 03:31:21

标签: php mysql html sql

有谁能告诉我为什么我的数据不会插入我的数据库?连接信息很好。我做错了什么?

<?php 
error_reporting();
include('include/config.php');
$strMsg="Signup, It's Free!";
?>
<html>
<head>
<title>Try This Fecal Matter</title>
</head>
<body>

<?php

    function validate($strMsg){
        //Validation upon Submit Click
            if(isset($_POST['submit'])){
            //Validate First Name Field
                if($_POST['fName']==""){
                    $strMsg="Please Enter Your First Name.";
                    showMForm($strMsg);
                }
            //Validate Last Name Field
                elseif($_POST['lName']==""){
                    $strMsg="Please Enter Your Last Name.";
                    showMForm($strMsg);
                }
            //elseif for validation of Email with a Regular Expression
                elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['eMail'])) {
                    $strMsg="Please Enter Your Email.";
                    showMForm($strMsg);
                }

            //Validate password
                elseif($_POST['pWord1']==""){
                    $strMsg="Please Enter A Password.";
                    showMForm($strMsg);
                }
                elseif($_POST['pWord2']!=$_POST['pWord1']){
                    $strMsg="Your Passowrds Do Not Match.";
                    showMForm($strMsg);
                }
else{

    $fName=$_POST['fName'];
    $lName=$_POST['lName'];
    $eMail=$_POST['eMail'];
    $pass=md5($_POST['pWord1']);




        /*$SQL="SELECT eMail FROM users WHERE eMail = '".$eMail."'";
                $rs = mysql_query($SQL);
echo $SQL;
            if($rs && mysql_num_rows($rs)>0){
                            $strMsg="Email Already Registered";
                            showForm($strMsg);
                }
            else{
    */
    //Send Content To Database..
//      $SQL = "INSERT INTO 'users' (`userID`, `fName`, `lName`, `eMail`, `pass`)    
VALUES (NULL,
    dbConnect();
    $SQL = "INSERT INTO users (`userID`, `fName`, `lName`, `eMail`, `pass`,    
`bgPic`,`bio`) VALUES (NULL,'$fName', '$lName', '$eMail', '$pass', NULL, NULL );";
            echo $fName."<br/>";
            echo $lName."<br/>";
            echo $eMail."<br/>";
            echo $pass."<br/>";
            //  }
                echo $SQL;
}
}
else
    showMForm($strMsg);

}






    function showMForm($strMsg){
        echo"<div id=\"form\">\n";
        echo"<h2>".$strMsg."</h2><br/>\n";
        echo" <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" >\n";
        echo"                   <p>First Name:<br/>\n";
        echo"                   <input type=\"text\" name=\"fName\" value=\"".$_POST['fName']."\"/></p>\n";
        echo"                   <p>Last Name:<br/>\n";
        echo"                   <input type=\"text\" name=\"lName\" value=\"".$_POST['lName']."\"/></p>\n";
        echo"                   <p>E-mail:<br/>\n";
        echo"                   <input type=\"text\" name=\"eMail\" value=\"".$_POST['eMail']."\"/></p>\n";
        echo"                   <p>Passwod:<br/>\n";
        echo"                   <input type=\"text\" name=\"pWord1\" value=\"\"/></p>\n";
        echo"                   <p>Re-Enter Passwod:<br/>\n";
        echo"                   <input type=\"text\" name=\"pWord2\" value=\"\"/></p>\n";   
        echo"                   <p>Regarding:<br/>\n";
        echo"                       <select name=\"state\">\n";
        echo"                           <option value=\"Ohio\">Ohio</option>\n";
        echo"                           <option value=\"Michigan\">Michigan</option>\n";
        echo"                           <option value=\"Indiana\">Indiana</option>\n";
        echo"                           <option value=\"Pensylvania\">Pensylvania</option>\n";
        echo"                       </select>\n";
        echo"                   <p><input type=\"submit\" value=\"Submit\" class=\"btnSubmit\" name=\"submit\" /></p>\n";
        echo" </form>\n";
}

        validate($strMsg);
?>
</body>
</html>

4 个答案:

答案 0 :(得分:0)

您似乎已注释掉 SQL查询

<强>例如:

   //Send Content To Database..
//      $SQL = "INSERT INTO 'users' (`userID`, `fName`, `lName`, `eMail`, `pass`)    
VALUES (NULL,
    dbConnect();
    $SQL = "INSERT INTO users (`userID`, `fName`, `lName`, `eMail`, `pass`,    
`bgPic`,`bio`) VALUES (NULL,'$fName', '$lName', '$eMail', '$pass', NULL, NULL );";
            echo $fName."<br/>";
            echo $lName."<br/>";
            echo $eMail."<br/>";
            echo $pass."<br/>";
            //  }

答案 1 :(得分:0)

嘿朋友你还没有使用mysql_query()功能。它在哪里?

mysql_query($SQL);

你已经完成了。

答案 2 :(得分:0)

mysql_query($sql);是您所缺少的......但同样重要的是,您还缺少在查询之前清理输入的部分。

要做到这一点:mysql_real_escape_string($value);

答案 3 :(得分:0)

此代码中有错误

$SQL = "INSERT INTO users (`userID`, `fName`, `lName`, `eMail`, `pass`,    
`bgPic`,`bio`) VALUES (NULL,'$fName', '$lName', '$eMail', '$pass', NULL, NULL );

致:

$SQL = "INSERT INTO users ( `fName`, `lName`, `eMail`, `pass`,) VALUES ('$fName', '$lName', '$eMail', '$pass');

问题可能是数据库mysql上的userID是主键吗?

我希望这项工作