newb: what's wrong with this if statement.
Moderator: General Moderators
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
newb: what's wrong with this if statement.
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.
<?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.
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>';
}
?>-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
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>';
?>