I have two option tags that I am retrieving data from a datatbase which I have working fine how ever I want to display users selection into PHP page and this is the part I can’t seem to get to work.
I don’t see any <form> tags around your <select>s, or a submit button, have you missed those out for clarity? And the code that displays the $_POST value is in a different script, and the “action” parameter on your <form> tag points correctly to it?
I’m a bit confused to the purpose of this last block of code.
On the third line you create an (apparently) unused variable by joining an empty string to the “Glitter” result, why?
On the last line you echo the “glitter” result along with the list of options in their option tags.
To me it would make more sense to do something like:-
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$glits = htmlspecialchars($_POST['Glitter']); // Make the user input 'safe' (trust no one)
// Any other form processing...
}
?>
…early on.
Then in the html something like:-
<?php if(isset($glits): ?>
<p>The glitter you chose was <?= $glits ?>.</p>
<?php endif ?>
The isset may be swapped for a more general condition to determine if the form has been processed, if there are a few results to print out.
Hi Sam thank you for your reply I had a go what you sent to me.
Sorry the html is message I new to Database and php so I am all over the place while i tring to get me\y head around it all.
I copied your text in to the html page and I received highlighted parts to the code. see pic. I tried semi-column just in case was i miss type but still have the same.
Looking at the image of the code the “request method” part should be first. Ideally before any html.
The first block of code you have, I’m not sure what it’s for.
Also, no need to go in and out of PHP all the time like that when there is a continuous block of php.