I'm a bit of a newbie to web devl and am learning how to code. I have taken the coding of a simple registration form and modified it to collect the added information I need. The whole thing is working perfectly until I bring in a couple of drop down lists. More perplexing is that if I leave the start of an orphaned <option tag at the end of each list it works great. The only draw back to this, is I then have a blank space among my options that is able to be selected and returns zero input to my database. I'm sure it's something very simple but with my limited experience, the solution has eluded me. I have searched and searched numerous coding forums and can not come up with any clues. The code (also attached in txt format) is as follows:
PHP Code:
<?php
// Check if he wants to register:
if (!empty($_POST["username"]))
{
// Check if passwords match.
if ($_POST["password"] != $_POST["password2"])
exit("Error - Passwords don't match. Please go back and try again.");
Removed the form tags around the dropdowns also removed the extra <option that wasn't closed or had an end tag. Removed the width=100% from the <td>'s because they don't belong there. Separated row content into two td's. (if your gonna use a table, use it.) Added a css section. Used the < and > to replace the < and > in the select values because they some times are read as ending the tag. Redid the register.php file. This is not completely correct but will do for now. You will need to check the user inputs and evaluate them before adding them to your database.
The is the HTML file:
// Check if he wants to register: if (!empty($_POST["username"])) { // Check if passwords match. if ($_POST["password"] != $_POST["password2"]) exit("Error - Passwords don't match. Please go back and try again.");
Many thanks for taking to time to review my code. Your revisions are an approach I had also tried myself, the result has been the same. When I open the page I get the following notices:
Notice: Undefined index: username in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 3
Notice: Undefined index: firstname in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 4
Notice: Undefined index: lastname in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 5
Notice: Undefined index: dateofbirth in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 6
Notice: Undefined index: occupation in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 7
Notice: Undefined index: livesin in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 8
Notice: Undefined index: postcode in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 9
Notice: Undefined index: income in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 10
Notice: Undefined index: password in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 11
Notice: Undefined index: password2 in C:\xampp\htdocs\KiwiChic\KiwiChic_Test_Copy\includes\register.php on line 12
You do not have a username entered.
The final note 'You do not have a username entered' I have not seen before. I might have mentioned earlier, I have been using XAMPP to develop my site before going live. Undefined indices are an issue I am finding with a couple of other scripts. Do you expect the scenario may be different once my website goes live (or maybe I'm well off the track)?
Again many thanks for your help, very much appreciated.
You can not run the register.php file by it's self. It is called from the main file that has the form that will define the first 12 items in the php file that I also gave you.
Quote:
final note 'You do not have a username entered' I have not seen before.
Correct, I added that. You should keep your users informed. If everything stops without an explanation they will think things are broke.
And again I warn:
Quote:
I echo out the query instead of adding to a database and commented out the require_once.