2017-03-31 13:27
浏览 74


So I am working on an app until I got an error which I can't figure out why this does not work, essentially the code is trying to put something in a database, which it is not doing. I got this error with it.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'id' at row 1' in /Users/DannyTran/Desktop/WebServer/social-network/classes/DB.php:10 Stack trace: #0 /Users/DannyTran/Desktop/WebServer/social-network/classes/DB.php(10): PDOStatement->execute(Array) #1 /users/DannyTran/Desktop/WebServer/social-network/register.php(24): DB::query('INSERT INTO use...', Array) #2 {main} thrown in /Users/DannyTran/Desktop/WebServer/social-network/classes/DB.php on line 10

Here is the code that I would have:

 CREATE TABLE `users` (
     `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `username` varchar(255) NOT NULL DEFAULT '',
      `first_name` varchar(255) NOT NULL DEFAULT '',
      `last_name` varchar(255) NOT NULL DEFAULT '',
      `email` varchar(255) NOT NULL DEFAULT '',
      `password` varchar(255) NOT NULL DEFAULT '',
      `gender` varchar(11) NOT NULL DEFAULT '',
      `country` varchar(255) NOT NULL DEFAULT '',
      `verified` int(11) NOT NULL,
      `role` varchar(255) NOT NULL DEFAULT '',
      `bio` text,
      `website` text,
      `status` text,
      `register` date NOT NULL,
      `last` date NOT NULL,
      `activated` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`)


    $pdo = new PDO('mysql:host=;DBname=socialnetwork;charset=utf8', 'root', 'password');

    if(isset($_POST['register'])) {
        $fn = strip_tags(@$_POST['fname']);
        $ln = strip_tags(@$_POST['lname']);
        $un = strip_tags(@$_POST['uname']);
        $em = strip_tags(@$_POST['email']);
        $pswd = strip_tags(@$_POST['password']);
        $pswd2 = strip_tags(@$_POST['password2']);
        $country = strip_tags(@$_POST['country']);
        $gender = strip_tags(@$_POST['gender']);
        $date = date("m-d-Y"); // Year - Month - Day
        $no = 0;
        $role = 'Member';
        $status = 'Hello world!';
        $website = '';  
        $bio = '';

        DB::query('INSERT INTO users VALUES (\'\' , :username, :first_name, :last_name, :email, :password, :gender, :country, :verified, :role, :bio, :website, :status, :register, :last, :activated)', array(':username'=>$un,':first_name'=>$fn, ':last_name'=>$ln, ':email'=>$em, ':password'=>$pswd, ':gender'=>$gender, ':country'=>$country, ':verified'=>0, ':role'=>$role, ':bio'=>$bio, ':website'=>$website, ':status'=>$status, ':register'=>$date, ':last'=>$date, ':activated'=>0));
        echo "Welcome!";


<h1>Register Now</h1>
        <form action="#" method="post">
            <input type="text" placeholder="First Name" name="fname" required/><br /><br />
            <input type="text" placeholder="Last Name" name="lname" required/><br /><br />
            <input type="text" placeholder="Username" name="uname" required/><br /><br />
            <input type="email" placeholder="E-Mail Address" name="email" required/><br /><br />
            <input type="password" placeholder="Password" name="pswd" required/><br /><br />
            <input type="password" placeholder="Confirm Password" name="pswd2" required/><br /><br />
            <select name="gender">
                <option value="" disabled selected>Gender</option>
                <option value="Male">Male</option>
                <option value="Female">Female</option>
                <option value="Other">Other</option>
            </select><br /><br />
            <?php require_once './options/countries.php'; ?><br /><br />
            <input name="register" type="submit" value="Login" /><br /><br />
        <a href="login.php">Have an account? Login!</a>



class DB {
        private static function connect() {
                $pdo = new PDO('mysql:host=;dbname=socialnetwork;charset=utf8', 'root', 'password');
                $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                return $pdo;
        public static function query($query, $params = array()) {
                $statement = self::connect()->prepare($query);
                // $data = $statement->fetchAll();
                // return $data;

I would appreciate any help I could get, thank you!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题