1- It is not accepting "Value" to be strings with spaces in it. I am not sure of the correct coding. How would I use value now that it is a sentence?:
Variables can not have spaces, and your trying to make "$Time Management and Delegation" into a variable. The "value" becomes a string the second you click the submit button.
I would not use [man]switch[/man] it works best for checking for 2 or more possible values in a variable. Use a simple if/else.
If you're not sure how to use an [man]array[/man] php.net has some great examples and user input.
Here is a simple example of an array
$coursearray = array(
'Time Management and Delegation',
'Modern Trends in Leadership and Supervision Skills',
'Modern Trends of Hospitals Management'
);
And you can loop through it like so
foreach ($coursearray as $key => $value ) {
echo '<option value="' . $key . '"> ' . $value . '</option>';
}
Just so you know the key is the numeric index for each array item. With 3 items in the array you have indexes 0-2.
And for what you need you will want to add an if/else in the loop
foreach ($coursearray as $key => $value ) {
if(isset($_POST['course']) && $key == $_POST['course']) {
echo '<option value="' . $key . '" selected> ' . $value . '</option>';
}
else {
echo '<option value="' . $key . '"> ' . $value . '</option>';
}
}
Real simple we just check if there is a value in "$_POST['course']" and if so see if it matches the "$key" if both are "true" then echo the <option> with it "selected". If either one is false then echo <option> without the "selected".
2- I tried the following switch function script ... however, I am getting this error after I test:
Read up on [man]header[/man]'s you can not have even a blank space output before you use [man]header[/man] and most certainly no HTML.
But I am really confused as to why you need to pass the value "$POST['course']" to a new page. And really it is bad idea to use GET especially on a publicly accessible page as the user can use their history to resubmit the data as well as they can to easily manipulate the data causing other problems. Further I would note that your not passing the other $POST values and so the rest of your validation code would not work once the page is reloaded with the redirect.
In your original post it sounds like you had the validation on the same page as the form I would continue doing it that way.
One last thought, don't use the short hand php tags for echoing.
<?=$error;?>
They have depreciated them and there was talk of them taking them out of PHP 6, but it sounds like they will keep them a bit longer. But they will be gone eventually and it could break your code. Use the full tag and echo function
<?php echo $error; ?>