Jump to content

[SOLVED] is this possible?


Lambneck

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.