0

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

<?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

4 回答 4

0

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

为此,请使用:mysql_real_escape_string($value);

于 2012-07-18T03:48:27.680 回答
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/>";
            //  }
于 2012-07-18T03:35:29.057 回答
0

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

mysql_query($SQL);

你就完成了。

于 2012-07-18T03:36:20.163 回答
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 上的用户 ID 是主键?

我希望这项工作

于 2012-07-18T04:33:07.037 回答