0
    $db = new PDO('mysql:host=localhost;dbname=dbname;charset=utf8', 'username', 'password');
    try
    {
        //Prepare and execute an insert into DB         
        $st = $db->prepare("INSERT INTO users(login,pass,email,county) VALUES(:username,:password,:email,:county)");        
        $st->execute(array(':username' => $_POST['username'], ':password' => $_POST['password1'], ':email' => $_POST['email'], ':county' => $_POST['county']));
        echo 'Success';
    }
    catch (PDOException $e)
    {
        echo $e->getMessage();
    }

Hi, I am not completely familiar with pdo but I thought I would add a few error exceptions, except I won't actually display the error normally as I don't want everyone to know my schema. In this case I changed my working code to a non working code by changing "...,county)" to "....,count)" which obviously did not insert into the database at all but still shown "Success" and no error.

Please help :(

1 Answer 1

1

You need to set PDO error mode to throw exception.

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but where should I put that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.