Page 1 of 1
newb: what's wrong with this if statement.
Posted: Tue Jun 17, 2003 2:59 pm
by slipstream
This will be real easy for you guy.
<?php
if ($cboDock==""){
echo 'You must select a value from the combo box above';
else{
$docketEntry=$date.'|'.$empName.'|'.$hours.'|'.$comment;
$file=fopen("dockets/".$cboDock.".txt", "a+");
fwrite($file, $docketEntry."\n");
fclose($file);
echo 'Hours recorded succesfully<br><a href=docket.html>Back to Docket</a>';
}
?>
I get an error, what's wrong with the if statement, I know $cboDock has a correct value in it.
Posted: Tue Jun 17, 2003 3:07 pm
by bjg
You didn't close the if statement.
Code: Select all
<?php
if ($cboDock==""){
echo 'You must select a value from the combo box above';
} // forgot this
else{
$docketEntry=$date.'|'.$empName.'|'.$hours.'|'.$comment;
$file=fopen("dockets/".$cboDock.".txt", "a+");
fwrite($file, $docketEntry."\n");
fclose($file);
echo 'Hours recorded succesfully<br><a href=docket.html>Back to Docket</a>';
}
?>
Posted: Tue Jun 17, 2003 3:11 pm
by slipstream
Duhhh, missed it. Thanks, it works now but for some reason doesn't think the combo box is equal to "".
It always runs the else command. Is there a way to check if the combo box is blank?
Posted: Tue Jun 17, 2003 3:17 pm
by bjg
Hmm, that should work. Play around with a few things like !$cboDock and empty($cboDock).
Posted: Tue Jun 17, 2003 3:26 pm
by slipstream
yep I already tried those combos..hmm I'll keep at it, thanks for your help.
Posted: Tue Jun 17, 2003 3:31 pm
by corlando
post your code that displays your combo box
Posted: Tue Jun 17, 2003 3:35 pm
by slipstream
echo 'Docket Numbers <select name="cboDock" size=1>';
foreach($file as $line)
{
$info = explode('|', $line);
echo '<option value="'.$info[0].'">'.$info[0].'</option>';
}
echo '</select><BR><BR>';
Posted: Tue Jun 17, 2003 8:13 pm
by corlando
Assuming that each element in your $file array has a value, your combo box (select box) by default selects the first option. By adding a static option before your loop and setting it's value to something that you know will not occur, you could then check for that value in your if statement. (see below)
Code: Select all
<?php
// change your if statement block to this
if ($cboDock == -1) {
?>
<?php
echo 'Docket Numbers <select name="cboDock" size=1>';
echo '<option value="-1">Please Select...</option>'; // INSERT THIS HERE
foreach($file as $line) {
$info = explode('|', $line);
echo '<option value="'.$info[0].'">'.$info[0].'</option>';
}
echo '</select><BR><BR>';
?>
Posted: Tue Jun 17, 2003 9:18 pm
by McGruff
slipstream wrote:Is there a way to check if the combo box is blank?
!isset($var)