ds3464 2015-03-26 12:19
浏览 55

PHP注册表不保存

I have a HTML Sign Up form that allows new users to be registered to the site.:

<form action="register.php" method="POST" class="register-form">
    <h1>Create Account</h1>
    <label>
        <span>First Name :</span>
        <input id="firstname" type="text" name="firstname" placeholder="Your First Name" autocomplete="off" required/>
    </label>
    <label>
        <span>Surname :</span>
        <input id="surname" type="text" name="surname" placeholder="Your Surname" autocomplete="off" required/>
    </label>
    <label>
        <span>Username :</span>
        <input id="username" type="text" name="username" placeholder="Your Chosen Username" autocomplete="off" required/>
    </label>
    <label>
        <span>Email :</span>
        <input id="email" type="email" name="email" placeholder="Your Email Address" autocomplete="off" required/>
    </label>
    <label>
        <span>Password :</span>
        <input id="password" type="password" name="password" placeholder="Your Chosen Password" autocomplete="off" required/>
    </label>
    <hr>
    <input name="action" type="hidden" value="signup" />
    <input type="submit" class="btn register btn-success btn-lg" name="submit" value="Register">

</form>

Which goes to register.php:

<?php
$connection = mysql_connect('localhost', 'root', 'password');
if (!$connection) {
    die("Database Connection Failed" . mysql_error());
}

$select_db = mysql_select_db('gmaps1');
if (!$select_db) {
    die("Database Selection Failed" . mysql_error());
}

// If the values are posted, insert them into the database.
if (isset($_POST['username']) && isset($_POST['password'])) {
    $firstname = $_POST['firstname'];
    $surname = $_POST['surname'];
    $username = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST['password'];


    $query = "INSERT INTO `users` (firstname, surname, username, password, email) VALUES ('$firstname', '$surname', '$username', '$password', '$email')";
    $result = mysql_query($query);
    if ($result) {
        header("Location: thank_you.html");
    } else {
        echo 'User Not Created';
    }
}
?>

But when I click the Register button it doesn't save the data and returns "User Not Created". Would it be better using MySQLi rather than MySQL or is there a better way for this to work??

  • 写回答

2条回答 默认 最新

  • dongzhuo2371 2015-03-26 12:31
    关注

    Error checking solved my problem - "field 'active' doesn't have a default value"

    There was an inactive field in the table 'Users'. I got rid of that and it works fine. It must have been added in by mistake.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?