Lambneck Posted August 28, 2008 Share Posted August 28, 2008 the following form submits data to a mysql database <form> <INPUT TYPE="radio" Name="color" VALUE="Red">Red<br> <INPUT TYPE="radio" Name="color" VALUE="Green">Green<br> <INPUT TYPE="radio" Name="color" VALUE="Blue">Blue<br> <INPUT TYPE="text" NAME="color_comments" SIZE=30><br> <INPUT TYPE="text" NAME="color_suggestions" SIZE=30><br> <INPUT TYPE="Submit" VALUE="Submit Message" Name="submit"> </form> what I want to make is a script that will recognize which color has been chosen in the form and then display the submitted form data based upon that color. I have separate pages (red.php, green.php, blue.php) that will display the form data that users submit based upon which color the user chose. for example all the submissions that had "Red" selected would be displayed in the page "red.php" and so on. My question is how do i get "red.php" to display all and only submissions that had the "Red" radiobutton selected? Quote Link to comment https://forums.phpfreaks.com/topic/121710-solved-is-this-possible/ Share on other sites More sharing options...
JonnoTheDev Posted August 28, 2008 Share Posted August 28, 2008 If the user details are submitting to a MYSQL database then surely you are storing the chosen colour. So in your red.php file your query may be: SELECT * FROM submissions WHERE colour='red' Quote Link to comment https://forums.phpfreaks.com/topic/121710-solved-is-this-possible/#findComment-627835 Share on other sites More sharing options...
obsidian Posted August 28, 2008 Share Posted August 28, 2008 My first question is, why do you have separate pages for all this? You could just simply update a single CSS declaration at the top of your receiving page to output the color you have chosen. Try something like this for fun: <?php $avail_colors = array('red', 'green', 'blue'); $color = isset($_POST['color']) && in_array(strtolower($_POST['color']), $avail_colors) ? strtolower($_POST['color']) : 'black'; echo <<<STARTCSS <style type="text/css"> body { color: $color; } </style> ?> <!-- Data gets spit out here --> Keep in mind that CSS should always be printed out in the header of an HTML document, but for simplicity's sake I just put it straight out here. Quote Link to comment https://forums.phpfreaks.com/topic/121710-solved-is-this-possible/#findComment-627840 Share on other sites More sharing options...
JonnoTheDev Posted August 28, 2008 Share Posted August 28, 2008 Im not sure where this guy is asking about CSS switching? I would definately do this with 1 page. If you have a colours DB table i.e. colours -------- id name Then your page can accept the id of the colour to get the desired results: mypage.php?id=3 $id = $_GET['id']; // do some filtering on $id then run in query mysql_query("SELECT * FROM tablename WHERE colourId='".$id."'"); P.S. I love the way you guys spell colour. Its just so wrong! LOL Quote Link to comment https://forums.phpfreaks.com/topic/121710-solved-is-this-possible/#findComment-627864 Share on other sites More sharing options...
DarkWater Posted August 28, 2008 Share Posted August 28, 2008 Color, favorite, patronize. > Take that, UK. Anyway, you know that you aren't supposed to post the exact same topic twice, right Lambneck? Quote Link to comment https://forums.phpfreaks.com/topic/121710-solved-is-this-possible/#findComment-627865 Share on other sites More sharing options...
Lambneck Posted August 28, 2008 Author Share Posted August 28, 2008 sorry bout the double post. thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/121710-solved-is-this-possible/#findComment-628103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.