PHP,PDO,MySQLi function dont insert to database

jeskey boneman

I make code that using pdo to insert information to database and gain XSS protection. now im few days look at the code and dont see the problem that make the code to not insert the requird information. Here`s My code:

if ($register = $mysqli->prepare("INSERT INTO `accounts`(`id`, `username`, `email`, `password`, `salt`, `fullname`, `birthdate`, `gender`, `secure question`, `secure answer`, `asked`, `answered`, `lastlogin`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
                    $register->bind_param("ssssssddsdds", $username, $email, $password, $random_salt, $fullname, $birthdate, $gender, $question, $answer, $z, $z, $lastlogin);
                    // Execute the prepared query.
                    if (! $register->execute()) {
                        echo "אירעה שגיאה";
                        $register->close();
                    }else{
                    echo 'אתם נרשמתם בהצלחה!. לחצו <a href="http://shaloti.com/users/login/">כאן</a>';}
                    $register->close();
                }

And the connection code:

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);

Thank you.

meda

Use mysqli_affected_rows to get the number of inserted row, if any function fails, check for errors using mysqli_error

$sql = "INSERT INTO `accounts`(`id`, `username`, `email`, `password`, `salt`, `fullname`, `birthdate`, `gender`, `secure question`, `secure answer`, `asked`, `answered`, `lastlogin`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if ($register = $mysqli->prepare($sql)) {
    $register->bind_param("ssssssddsdds", $username, $email, $password, $random_salt, $fullname, $birthdate, $gender, $question, $answer, $z, $z, $lastlogin);
    // Execute the prepared query.
    if (!$register->execute()) {
        echo "אירעה שגיאה";
        die("execute() failed: ". mysqli_error($mysqli));
    }

    if(mysqli_affected_rows($register) > 0){
        echo 'אתם נרשמתם בהצלחה!. לחצו <a href="http://shaloti.com/users/login/">כאן</a>';
    }else{
        echo 'Did not inser any row';
    }
}else{
    die("prepare() failed: ". mysqli_error($mysqli));
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to unit test a database insert function PDO

From Dev

pdo, insert php object to database

From Dev

PHP/SQL Multi INSERT INTO dont work

From Dev

How to insert data into the database using mysqli in php

From Dev

mysqli insert to database not working

From Dev

how to make an insert function with in a database class to insert a new record with multiple coloumns and multiple values (using PDO )?

From Dev

php pdo insert datas using function

From Dev

Using explode function in PHP and insert into a database using for loop

From Dev

Insert into wordpress database - Call to a member function insert()

From Dev

PHP mysqli_insert_id() Function without INSERT

From Dev

PHP - why this LIST function dont work

From Dev

PDO data not insert into database no error

From Dev

Insert Object entries into database with PDO

From Dev

PHP MySQL Insert database

From Dev

Insert datetime into database PHP

From Dev

Insert in Database with PHP variable

From Dev

PHP MySQL Insert database

From Dev

Insert MYSQL PHP into database

From Dev

why php mysqli does not insert data to database in Xampp

From Dev

PHP / Mysqli Insert Statement isn't writing to database

From Dev

Insert multiple values via PHP PDO into MySQL database

From Dev

run insert query once only when the database is created php pdo

From Dev

md5 hash compare to database dont work php

From Dev

Function with insert mysqli throwing error

From Dev

I can't access the database with this set of code. Using both PDO and another method, and they dont acess the config.php

From Dev

How do i write a function to insert into database

From Dev

Create insert function in php

From Dev

Insert PHP within function

From Dev

Insert function script php

Related Related

  1. 1

    How to unit test a database insert function PDO

  2. 2

    pdo, insert php object to database

  3. 3

    PHP/SQL Multi INSERT INTO dont work

  4. 4

    How to insert data into the database using mysqli in php

  5. 5

    mysqli insert to database not working

  6. 6

    how to make an insert function with in a database class to insert a new record with multiple coloumns and multiple values (using PDO )?

  7. 7

    php pdo insert datas using function

  8. 8

    Using explode function in PHP and insert into a database using for loop

  9. 9

    Insert into wordpress database - Call to a member function insert()

  10. 10

    PHP mysqli_insert_id() Function without INSERT

  11. 11

    PHP - why this LIST function dont work

  12. 12

    PDO data not insert into database no error

  13. 13

    Insert Object entries into database with PDO

  14. 14

    PHP MySQL Insert database

  15. 15

    Insert datetime into database PHP

  16. 16

    Insert in Database with PHP variable

  17. 17

    PHP MySQL Insert database

  18. 18

    Insert MYSQL PHP into database

  19. 19

    why php mysqli does not insert data to database in Xampp

  20. 20

    PHP / Mysqli Insert Statement isn't writing to database

  21. 21

    Insert multiple values via PHP PDO into MySQL database

  22. 22

    run insert query once only when the database is created php pdo

  23. 23

    md5 hash compare to database dont work php

  24. 24

    Function with insert mysqli throwing error

  25. 25

    I can't access the database with this set of code. Using both PDO and another method, and they dont acess the config.php

  26. 26

    How do i write a function to insert into database

  27. 27

    Create insert function in php

  28. 28

    Insert PHP within function

  29. 29

    Insert function script php

HotTag

Archive