Solved

variable

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

773 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