Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

variable

Posted on 2004-04-10
5
Medium Priority
?
214 Views
Last Modified: 2008-02-20
I would like to create a form that would aloud my user to change several variable on the site.

Form will ask:

What color for the background?
 
What name to use?

Then went the user submit the form the response will be included the actual site.

The background would be “Blue” or “Red” or whatever color the user included.

I Have the form completed with all the fields, I also created the web page now how do I get the two to work together.

All I need is maybe a tutorial or a url with reference as to how to get this done.

Thanks

RCLeon
0
Comment
Question by:rcleon
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10797387
you have to simple html forms  to send that information to php
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10797411
<?php
      
      if((isset($_REQUEST['clr'])) && ($_REQUEST['clr']!=""))
      {
            $bgcolor = $_REQUEST['clr'];

            print "<BODY bgcolor=$bgcolor>";
      }
?>


<form name=htmldetails>
<input type=text name=clr value='#660033'>
<input type=submit name=submit value=sub>
<form>
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10797415
I did not understand why you need name..
0
 
LVL 5

Expert Comment

by:TheClickMaster
ID: 10797730
You should use SESSIONS

Do not include anything else before the <?php.

<?php
     if(isset($_POST['customize']) && $_POST['color'] != "" && $_POST['uname'] != "")
     {
          session_register(user_name);
          session_register(user_color);
     
          $_SESSION["user_name"] = $_POST['uname'];
          $_SESSION["user_color"] = $_POST['color'];
     }

     if(!session_is_registered(user_name))
     {
         print "<form action='testdatabase.php' method='POST'>
                 Color: <input type='text' name='color'><br>
                 Name: <input type='text' name='uname'><br>
                 <input type='submit' value='Update' name='customize'>
                 </form>";
     }

     print "<html><body bgcolor='".$_SESSION["user_color"]."'>";
     if(session_is_registered(user_name))
       {
             print "Welcome, ".$_SESSION["user_name"];
       }
       else
       {
          print "You are an unknown person!";
       }
     print "</body></html>";
?>
0
 
LVL 5

Accepted Solution

by:
TheClickMaster earned 2000 total points
ID: 10797901
Finally, a even better solution is to use cookies. The values will remain saved in the users browser so he doesnt have to set it every time he goes to your website

<?php

      // if the form was submited
     if(isset($_POST['customize']) && $_POST['color'] != "" && $_POST['uname'] != "")
     {
             // set cookies with the values
          setcookie("user_name",$_POST['uname'],time()+60*60*24*365*20);
          setcookie("user_color",$_POST['color'],time()+60*60*24*365*20);
              $_COOKIE["user_name"] = $_POST['uname'];
              $_COOKIE["user_color"] = $_POST['color'];
     }
      
       // if the user wants to change the settings
       if(isset($_GET["remove_customization"]))
       {
             // clear the cookies
        setcookie("user_name","");
        setcookie("user_color","");
            unset($_COOKIE["user_name"]);
            unset($_COOKIE["user_color"]);
       }

      // if the users name is not saved in a cookie we display the form
     if(!isset($_COOKIE["user_name"]))
     {
         print "<form action='testdatabase.php' method='POST'>
                 Color: <input type='text' name='color'><br>
                 Name: <input type='text' name='uname'><br>
                 <input type='submit' value='Update' name='customize'>
                 </form>";
     }
       else
       {
             // else we display a link to change the settings
             print "<a href='testdatabase.php?remove_customization=1'>Change settings</a><br><br>";
       }

      // set the background color
     print "<html><body bgcolor='".$_COOKIE["user_color"]."'>";
      
       // if we have a username
     if(isset($_COOKIE["user_name"]))
      {
                    // display it
           print "Welcome, ".$_COOKIE["user_name"];
      }
      else
      {
                    // display generic text (or nothing...)
         print "You are an unknown person!";
      }
     print "</body></html>";
?>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question