I cannot insert data into databae with php pdo | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

I cannot insert data into databae with php pdo

Hello guys I cannot figure out what is wrong with this code why it does not send information to database can anyone try it for me if there is just problem with my database connection which probably not because I used try and catch and everything looks fine --- ``` else { $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $username = $_POST['username']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); include_once 'database.php'; $query = "USE". $database . "INSERT INTO USERS(FIRST, LAST, EMAIL, USERNAME, PASSWORD) VALUES (:FIRST, :LAST, :EMAIL, :USERNAME, :PASSWORD))"; $sql = $connect->prepare($query); $fields = array( ':FIRST' => $first, ':LAST' => $last, ':EMAIL' => $email, ':USERNAME' => $username, ':PASSWORD' => $password, ); $sql->execute($fields); $code = $sql->errorCode(); $error = '<div class="alert alert-danger" role="alert">ERROR CODE :' . $code . '! </div>'; } ``` ---

14th Apr 2020, 2:53 PM
Jalal Mitali
Jalal Mitali - avatar
1 Antwort
0
Why :FIRST in insert INTO And not $first ...and So on next variables?
27th May 2021, 8:27 PM
Václav Dostál
Václav Dostál - avatar