某些值未显示在mySQL数据库中

时间:2013-12-06 01:05:50

标签: php mysql sql

我正在使用phpMyAdmin来存储数据库。问题是当我进行插入查询时,只有3个字段已满,其中2个被忽略。

enter image description here

是的,我已经阅读了其他答案但到目前为止没有运气。如果我手动添加客户,名称和姓氏将显示在那里。我删除了我手动插入的那些,因此表中没有c_id 3和4。

这是registration.php的代码:

    <?php
    if(isset($_GET['error']))
        echo $_GET['error'];
    ?>
    <form action = "register.php" method = "POST">
    <label>Password: <input type = "password" name = "password"> <label/> <br/>
    <label>Confirm password: <input type = "password" name = "password_again"> <label/><br/>
    <label>First name: <input type = "text" name = "fname"> <label/><br/>
    <label>Last name: <input type = "text" name = "lname"> <label/><br/>
    <label>Address: <input type = "text" name = "address"> <label/><br/>
    <input type = "submit" name = "register" value = "Register"/><br/>
    </form>

register.php:

<?php
if(isset($_POST['register']))
{
    require "db.php";
$password =md5(strip_tags($_POST['password']));
    $password_again = md5(strip_tags($_POST['password_again']));
    $firstname = strip_tags($_POST['fname']);
    $lastname = strip_tags($_POST['lname']);
#$firstname = $_POST['firstname'];
#$lastname = $_POST['lastname'];
$address = strip_tags($_POST['address']);
/*echo $firstname;
echo $lastname;*/
if($password == '' || $password_again == '' || $firstname = '' || $lastname = '' || $address == '')
{
    header('location:./registerform.php?error=empty fields');
    exit();
}
if(!strcmp($password, $password_again)==0)
{
    header('location:./registerform.php?error=passwords not matching');
    exit();
}
$sql = "INSERT INTO customers VALUES (NULL, '$password', '$firstname', '$lastname', '$address')";
mysql_query($sql);
#mysql_query("INSERT INTO customers(C_ID, C_PWD, C_FNAME, C_LNAME, C_ADD) VALUES(NULL, '$password', '$firstname', '$lastname', '$address')") or die("".mysql_error());

    #echo $firstname;
    #echp $lastname;
echo "Registered. Please login with your ID ".mysql_insert_id(). ".";
echo "<br/><a href = 'loginform.php'>Login here</a>";

}   
else
{
    header('location:registration.php');
    exit();
}
?>

db.php代码:

<?php
$name = "root";
$pas = "";
$dbname = "webstore";
$connection = mysql_connect("localhost", $name, $pas) or die ("Could not connect");
$selection = mysql_select_db($dbname, $connection) or die ("Could not select the db");
?>

对于dubugging目的,我试图打印$ firstname和$ lastname,它们是在从表单中检索时打印的,但如果是在查询之后没有打印。有什么建议?提前致谢

0 个答案:

没有答案