I had missed a parenthese.PHP Code:return (isset($_POST[$_index])) ? $_POST[$_index] : '';
Your select box markup is a bit messed up. Do you want to let the user choose more then the current entry, which hasn't even got a name in your code?
| SitePoint Sponsor |
I had missed a parenthese.PHP Code:return (isset($_POST[$_index])) ? $_POST[$_index] : '';
Your select box markup is a bit messed up. Do you want to let the user choose more then the current entry, which hasn't even got a name in your code?


Hi
I simply want the previous selected option to be selected once again. If no option is selected, then it be blank (again) so they can select it.
The original code for that part was:
So I was just wondering how to adjust this using your code.PHP Code:<td><select name="createdby_select" id="createdBy">
<OPTION SELECTED VALUE="">---------------</OPTION>
<?php
while ($createdby_q = mysql_fetch_array($createdby_query)) {
$createdby_id = $createdby_q["createdbyID"];
$createdby_name = $createdby_q["createdbyName"];
echo("<OPTION VALUE='$createdby_id'>$createdby_name<BR>\n");
}
?>
</select></td>
Thanks.
Mak![]()
PHP Code:/* Ignore this line */ ?>
<td>
<select name="createdby_select" id="createdBy">
<option value="">---------------</option>
<?php
$preselection = safe_post('createdby_select');
while ($createdby_q = mysql_fetch_array($createdby_query)) {
$selected = ($preselection == $createdby_q['createdbyID']) ? 'selected' : '';
echo '<option '.$selected.' value="'.$createdby_q['createdbyID'].'>'.
$createdby_q['createdbyName'].'<br>'."\n";
}
?>
</select>
</td>


Hi
I tried that but something odd happens.
The options I can select are:
1. Myself
2. Parent
3. Guardian
4. Other family member
5. Friend
When I select 'Myself' and post the form with the rest blank, it brings up the appropriate error messages and I would expect it to have 'Myself' selected again. Instead, it has:
"--------------
Parent
Other family member
Forename"
Equally, similar odd stuff happens when I select any other option. What I don't understand is where it is getting 'Forename' from? Is something wrong with the way I am accessing the $_POST array?
Thanks.
Mak![]()
In the while loop echo out $createdby_q['createdbyName'], $createdby_q['createdbyID'] and $selected after the echo please.


Hi
Sorry for being thick but do you mean:
?PHP Code:<?php
$preselection = safe_post('createdby_select');
while ($createdby_q = mysql_fetch_array($createdby_query)) {
$selected = ($preselection == $createdby_q['createdbyID']) ? 'selected' : '';
//echo '<option '.$selected.' value="'.$createdby_q['createdbyID'].'>'.$createdby_q['createdbyName'].'<br>'."\n";
echo '<option '.$selected.' value="">'\n";
}
?>
Thanks.
Mak![]()
after the echo of the option tag. This is for debugging reasons, to know that is fetched from the database and what the data generates.PHP Code:echo 'Name: ' , $createdby_q['createdbyName'] , ' ID: ' , $createdby_q['createdbyID'] , ' Selected: ' , $selected' , ' Preselection: ' , $preselection , '<br />';


Hi
With that I get:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'
Any ideas?
Thanks.
Mak![]()
Sorry one quote to much.
PHP Code:echo 'Name: ' , $createdby_q['createdbyName'] , ' ID: ' , $createdby_q['createdbyID'] , ' Selected: ' , $selected , ' Preselection: ' , $preselection , '<br />';


Hi
Then I get (in the re-displayed select box):
->Parent Name: Parent ID: 2: Preselection: 1
->Other family member Name: Other family member ID: 4 Selected: Preselection: 1
->Forename
Those are the three options it shows. What's odd is the 'Forename' as that is, as yet, just the next field:
Hope that helps?PHP Code:<tr>
<td width="223">Forename</td>
<td width="241">
<input name="mForename" type="text" id="mForename" size="25" maxlength="25">
</td>
</tr>
Oh, btw, the database code is:
Thanks.Code:# Table structure for table `createdby` # CREATE TABLE `createdby` ( `createdbyID` int(1) NOT NULL auto_increment, `createdbyName` varchar(20) default NULL, PRIMARY KEY (`createdbyID`) ) TYPE=MyISAM AUTO_INCREMENT=6 ; # # Dumping data for table `createdby` # INSERT INTO `createdby` VALUES (1, 'Myself'); INSERT INTO `createdby` VALUES (2, 'Parent'); INSERT INTO `createdby` VALUES (3, 'Guardian'); INSERT INTO `createdby` VALUES (4, 'Other family member'); INSERT INTO `createdby` VALUES (5, 'Friend');
Mak![]()
Can I have the full source, I would need everything to be able to successfully debug it. Thanks.![]()


Hi
It was a bit long to post so I have PM'd you it in sections.
Thanks.
Mak![]()
Yes, I will look into it tommorrow.![]()


Hi
Look foward to your reply
Thanks.
Mak![]()
Okay, I attached the PHP file, I hope it helps you.![]()


Hi
Where is the attached PHP file?
Thanks.
Mak![]()
You have to wait till it is approved.


Hi
I still can't see anything.. either here or in private messages.. and it has been a couple of days?
Thanks.
Mak![]()
I see it now.


Hi
Thanks for that!
I just tried it and get this:
Parse error: parse error, unexpected ';' in d:\inetpub\wwwroot\site\join_form.php on line 6
I think it is referring to this line:Thanks.PHP Code:return (isset($_POST[$_index]) ? $_POST[$_index] : '';
Mak![]()





Should be
PHP Code:return (isset($_POST[$_index])) ? $_POST[$_index] : '';


Hi
I fixed that but then I get:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in d:\inetpub\wwwroot\site\join_form.php on line 39
I thought it may be some missing parentheses but that didn't work.PHP Code:$selected = ($preselected == $createdby_id) 'selected' : '';
Any ideas?
Thanks.
Mak![]()
Must be
PHP Code:$selected = ($preselected == $createdby_id) ? 'selected' : '';


Hi
What about:
Parse error: parse error, unexpected '=' in d:\inetpub\wwwroot\site\join_form.php on line 84
Thanks.PHP Code:$preselection = safe_post('day_select');
Mak![]()
I hopefully cleared out some of the errors, see the attached file.
Bookmarks