I’m learning how to create registration/login forms, how to insert data from forms into databases, etc.
I found a great tutorial @ http://www.bewebdeveloper.com/tutorial-about-using-ajax-with-phpmysql I downloaded the source code and had a form that let me add and delete rows from a database table. I then found a registration form that I like better (though it has no associated database table) @ http://jqueryvalidation.org/files/demo/milk/
So I tried to combine the two, and I thought I had it figured out, but it isn’t working. You can see my test page @ http://www.govwa.org/test/registration.php
When I fill out the form and click the Submit button, I see the message “Submitted!” But my local database table remains unchanged. When I do the same thing online, a new row is added to my online table, but the value for every field is NULL.
At the bottom of the test page, you’ll see the error message “PDOException : SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘age’ cannot be null”
I got the same message on my local page. I fixed it by changing the Default value of every field from None to NULL. I changed the last field’s value back to None to let you see the error message.
Does anyone have a hunch what’s going on, or do you know how I can troubleshoot this form?
Here’s the PHP code that appears just before the form’s closing tag. (I wasn’t sure if I should post this in the JavaScript or PHP forum.)
include('ajax-database/config.php');
$pdo = connect();
try {
$sql = "INSERT INTO g1_members (firstname, lastname, username, password, password_confirm, email, age) VALUES (:firstname, :lastname, :username, :password, :password_confirm, :email, :age)";
$query = $pdo->prepare($sql);
$query->bindParam(':firstname', $_GET['firstname'], PDO::PARAM_STR);
$query->bindParam(':lastname', $_GET['lastname'], PDO::PARAM_STR);
$query->bindParam(':username', $_GET['username'], PDO::PARAM_STR);
$query->bindParam(':password', $_GET['password'], PDO::PARAM_STR);
$query->bindParam(':password_confirm', $_GET['password_confirm'], PDO::PARAM_STR);
$query->bindParam(':email', $_GET['email'], PDO::PARAM_STR);
$query->bindParam(':age', $_GET['age'], PDO::PARAM_STR);
$query->execute();
} catch (PDOException $e) {
echo 'PDOException : '. $e->getMessage();
}
Thanks!