Solved

variable

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Time difference 10 35
Codiing Non-Existent Links 4 28
Post xml via PHP Soap Client 3 10
inserting while loop results 2 7
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now