Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

variable

Posted on 2004-04-10
5
Medium Priority
?
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

688 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