Solved

variable

Posted on 2004-04-10
5
208 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

626 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