Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Patrick Nel
Patrick Nel
3,544 Points

Creating a registration form with PHP & MySQL

Hi Guys I have had very little sleep trying to get this registration process to work. I am using a PHP & MySQL book and also my own input to get this to work. I have gone over everything 1000 times but just cant figure it out.

The user would log in on the (/new_user/index.php) and a separate page will do the form handling (/new_user/register-process.php), if successful then they are redirected to (success.php) with the option to log in (my next challenge).

I've attached the link to Github with the files.

https://github.com/stickfish/testing

The database I created already using workbench before the registration page. The connection details to link to DB are CONSTANTS defined outside of these docs I confirmed they were correct.

When I submit the form it either gives me an error "Problem registering account" (from the FINAL CHECKS section) or nothing happens. But either way the database doesn't get the data and it never redirects to success.php.

Sorry for mile long question.

Thank you for your assistance, Treehouse way better than stackoverflow especially when you have an issue.

2 Answers

Hey!

It sounds like you might have done this already, but I would start off by checking key values from start to finish:

<?php
echo $keyValue;
exit;

Once you're absolutely 100% sure that everything is being set properly, then something else is wrong.

E.g. you're passing $_POST into your register user function, and you've labelled that argument $userData.

BUT you never seem to call $userData again, you're still accessing the post stuff. You've already past the form data into your function so there's no need for things like this:

<?php

$username = $mysqli->real_escape_string($_POST['username']);

when you should be doing this:

<?php

$username = $mysqli->real_escape_string($userData['username']);

I would add some test code to the very top of your function:

<?php

echo "<pre>:;
var_dump($userData);
exit;

and find out if your'e successfully passing those values through.

Patrick Nel
Patrick Nel
3,544 Points

Thanks so much Tom, I will give this a try and let you know how it turned out.