+ 2

Im making a registration form Whats the problem here. Output: not prepare..

help https://code.sololearn.com/wZlXL6YGJ6Wc/?ref=app

16th Feb 2018, 11:50 AM
Salag Mailliw
Salag Mailliw - avatar
5 Respuestas
+ 3
I would suggest using my below code and adapting to your needs, this is using the latest from PDO, PHP7, and is cleaner and easier to read than your example. <?php $host = 'localhost'; $user = 'username'; $pass = 'password'; $database = 'my_database'; $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ); $pdo = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options); $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $sql = "INSERT INTO `users` (`first_name`, `last_name`) VALUES (:first_name, :last_name)"; $statement = $pdo->prepare($sql); $statement->bindValue(':first_name', $first_name); $statement->bindValue(':last_name', $last_name); $inserted = $statement->execute(); if($inserted){ echo'Inserted'; } else { echo'Not Inserted'; } ?>
16th Feb 2018, 12:03 PM
ihateonions
+ 3
.. thanks brother.
16th Feb 2018, 12:29 PM
Salag Mailliw
Salag Mailliw - avatar
+ 2
thats pdo right?
16th Feb 2018, 12:04 PM
Salag Mailliw
Salag Mailliw - avatar
+ 2
thanks a lot .
16th Feb 2018, 12:05 PM
Salag Mailliw
Salag Mailliw - avatar
+ 1
Yeah thats correct, PDO, so you don't need to use mysqli_real_escape_string to escape data as PDO can handle that for you.
16th Feb 2018, 12:16 PM
ihateonions