Reputation: 5
I am working on a form to create an athlete forename and surname. This works as it should, populating the appropriate parts of the database.
I have now come to add a drop down box in which they will select the athlete's country. Unfortunately, I cannot get this to show up in the athletecountry field of the database. This is in the same table as forename and surname.
I would hugely appreciate any help.
<?php echo ($error != "") ? $error : ""; ?>
<form action="createathlete.php" method="post">
<br>
<br>
Athlete Forename: <input type="text" value="<?php echo $athleteforename; ?>" name="athleteforename" /><br/>
Athlete Surname: <input type="text" value="<?php echo $athletesurname; ?>" name="athletesurname" /><br/>
Representing: Country: <select name=$athletecountry tabindex="1">
<optgroup label="Continent">
<option value="Country 1">Country 1</option>
<option value="Country 2">Country 2</option>
<option value="Country 3">Country 3</option>
</optgroup>
</select>
<input type="submit" value="Register" name="submit-form" />
</form>
Earlier in the page I also have this code which I cobbled together from a couple of other tutorials.
//initialize php variables used in the form
$athleteforename = "";
$athletesurname = "";
$userID = "";
$athletecountry = "";
//check to see that the form has been submitted
if(isset($_POST['submit-form'])) {
//retrieve the $_POST variables
$athleteforename = $_POST['athleteforename'];
$athletesurname = $_POST['athletesurname'];
$athletecountry = $_POST['athletecountry'];
//initialize variables for form validation
$success = true;
$userTools = new UserTools();
//prep the data for saving in a new user object
$data['athleteforename'] = $athleteforename;
$data['athletesurname'] = $athletesurname;
$data['athletecountry'] = $athletecountry;
$data['userID'] = $user->id;
//create the new user object
$newAthlete = new Athlete($data);
//save the new user to the database
$newAthlete->save(true);
Upvotes: 0
Views: 54
Reputation: 16
As per @Chandu and @taxicala answers, once the code is showing as "athletecountry" that should be fine.
Check that the Athlete() class is expecting all the elements in the array, perhaps the country string is being dropped because it's unexpected for some reason?
Upvotes: 0
Reputation:
It seems you are not giving proper name to select i.e $athletecountry
<select name=$athletecountry tabindex="1">
change to
<select name="athletecountry" tabindex="1">
Upvotes: 1
Reputation: 21759
You have a typo in the name attr of the select:
Change:
<select name=$athletecountry tabindex="1">
To:
<select name="athletecountry" tabindex="1">
Upvotes: 0