php - PDO not throwing errors -


i have following code insert new record in database:

<?php  require('comune.php'); $nome = $_post['nome']; $username = $_post['username']; $segreto = $_post['password']; $password = md5($segreto); $validity = $_post['validity']; $ruolo = $_post['ruolo']; $funzione = $_post['funzione']; list($giorno, $mese, $anno) = explode('/', $validity); $validity = implode('-', array($anno, $mese, $giorno));  try {     $sql = "insert utenti "             . "(nome,username,segreto,password,validity,ruolo,funzione) "             . "values ('$nome', '$username', '$segreto', '$password', '$validity', '$ruolo', '$funzione')";     $s = $pdo->prepare($sql);     $s->execute(); } catch (pdoexception $e) {     $message = "ko"; } $message = "ok"; //echo $sql; echo $message; ?> 

the issue facing that, if query returns error, $message "ok". doing wrong??

change code to

$sql = "insert utenti (nome,username,segreto,password,validity,ruolo,funzione) "         . "values (?,?,?,?,?,?,?)"; $s = $pdo->prepare($sql); $s->execute([$nome, $username, $segreto, $password, $validity, $ruolo, $funzione]); echo "ok"; 

you have either ok or informative error message


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -