We help IT Professionals succeed at work.

Content Not Being Added to Database via Form

dgarofalo
dgarofalo asked
on
I am having trouble adding names to the database. The page that displays the contents of the database works fine. I set error reporting to ALL and still can't get the addition to the database to go through. Could someone point me in the right direction? Attached are the files. Thank you.
simpledb.zip
Comment
Watch Question

Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
Hi there,

You're likely to get more help here if you post up the code for the part you're having problems with. By posting up a zip file, you're asking us to download, upzip and then dig through your entire application to guess what the problem is. Many experts simply won't bother.

If you post up the page that submits your data to the server (a form?), and the script that inserts that data into the DB, it'll be much easier for us to take a look at.
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
OK,

I've just had quick look at your code, and I think the culprit is your INSERT statement. Your statement is like this:

INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES (' ', ?, ?, ?, ?, NOW() )

You're trying to insert 6 values into 5 columns. What's the empty ' ' all about. You don't need that, so you should remove it:

INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES (?, ?, ?, ?, NOW() )

Author

Commented:
Thanks, Chris. I found the problem. I had the wrong file listed in the action attribute. Next time I post something, I will be sure to follow what you suggested.
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
OK, No worries. Take a look at your insert query though because that does look wrong.

Another suggestion :) In your connect script, you're instantiating the connection as an Object (new mysqli()), and you're using try/catch blocks, so you're half way towards writing Object Oriented Code. But then throughout the rest of your code, you've reverted back to the old-school procedural style. It will make your code a lot clearer if you stick with the OOP way of doing things, for example instead of doing this:

mysqli_stmt_prepare($q, $query);
mysqli_stmt_bind_param($q, 'ssss', $first_name, $last_name, $email, $hashed_passcode);
mysqli_stmt_execute($q);

Open in new window


Do this:

$stmt = $dbcon->prepare($query);
$stmt->bind_param('ssss', $first_name, $last_name, $email, $hashed_passcode);
$stmt->execute();

Open in new window

Author

Commented:
Thanks, Chris!