Jump to content

aidoDel

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

aidoDel's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi I'm trying to build an application where a user enters their birthday into a HTML form and it gets processed by php to return their starsign. I am a complete newbie to php and I'm getting stuck with some simple logic. Any help would be great. My HTML FORM IS: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Smart Forms JS</title> <script type="text/javascript" src="js/smartform.js"</script> <link rel="stylesheet" href="css/style.css" /> </head> <body> <h2 align="center">What your future holds</h2> <div id="form-area"> <!--<form action="users_details.php" method="post">--> <form action="new2.php" method="post"> <fieldset> <legend>Your Personal Details</legend> <p> Please enter your date of birth: <br /> <label for="user_day">Day:<input name="user_day" id="user_day" type="text" size="2" class="reqd" maxlength="2" onkeypress="return isNumberKey(event)"></label> <label for="user_month">Month: <select name="user_month" id="user_month" class="reqd"> <option value="" selected="selected">Choose a month</option> <option value="January">January</option> <option value="February">February</option> <option value="March">March</option> <option value="April">April</option> <option value="May">May</option> <option value="June">June</option> <option value="July">July</option> <option value="August">August</option> <option value="September">September</option> <option value="October">October</option> <option value="November">November</option> <option value="December">December</option> </select> </label> <label for="user_year">Year:<input name="user_year" id="user_year" type="text" size="4" class="reqd" maxlength="4" onkeypress="return isNumberKey(event)" ></label> </p> <p> <input name="submit" type="submit" /> <input name="reset" type="reset" /> </p> </fieldset> </form> </div> </body> </html> AND SO FAR MY PHP IS: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Processed Form</title> <link rel="stylesheet" href="css/style.css" /> </head> <body> <div id="wrapper"> <h2>Processed Form from Birthday Page</h2> <?php $starsign[0] = array('name'=>'Capricorn', 'description' =>'description of capricorn people'); $starsign[1] = array('name'=>'Aquarius', 'description' =>'description of aquarius people'); $starsign[2] = array('name'=>'Pisces', 'description' =>'description of Pisces people'); $starsign[3] = array('name'=>'Aries', 'description' =>'description of aries people'); $starsign[4] = array('name'=>'Taurus', 'description' =>'description of Taurus people'); $starsign[5] = array('name'=>'Gemini', 'description' =>'description of Gemini people'); $starsign[6] = array('name'=>'Cancer', 'description' =>'description of Cancer people'); $starsign[7] = array('name'=>'Leo', 'description' =>'description of Leo people'); $starsign[8] = array('name'=>'Virgo', 'description' =>'description of Virgo people'); $starsign[9] = array('name'=>'Libra', 'description' =>'description of Libra people'); $starsign[10] = array('name'=>'Scorpio', 'description' =>'description of Scorpio people'); $starsign[11] = array('name'=>'Sagittarius', 'description' =>'description of Sagittarius people'); $month = $_POST['user_month']; $day = $_POST['user_day']; $year = $_POST['user_year']; $user_starsign = $starsign[$group]['name']; $description = $starsign[$group]['description']; function star_sign($month, $day, $year) { $time = mktime(0, 0, 0, $month, $day, $year); //return the Unix timestamp $day_of_year = date("z", $time); // "z" is equal to the day of the year 0 to 365 if (date("L", $time) && ($day_of_year > 59)) // for leap years "L" is LEAP YEAR $day_of_year -= 1; // if it is FEB 29 (59) Subtract 1 from the day of year switch ($day_of_year) { case $day_of_year > 356: // above 22nd Dec = Capricorn return "Capricorn"; case $day_of_year > 326: return "Sagittarius"; case $day_of_year > 296: return "Scorpio"; case $day_of_year > 266: return "Libra"; case $day_of_year > 235: return "Virgo"; case $day_of_year > 203: return "Leo"; case $day_of_year > 172: return "Cancer"; case $day_of_year > 140: return "Gemini"; case $day_of_year > 111: return "Taurus"; case $day_of_year > 78: return "Aries"; case $day_of_year > 51: return "Pisces"; case $day_of_year > 20: return "Aquarius"; default: return "Capricorn"; } } echo "Your star sign is " . star_sign($month, $day, $year); ?> </div> My first major problem is that the php only ever returns the first case of function star_sign which is "Capricorn" irrespective of what date is entered. My second problem is that I don't what to return a string in the function, I want it to return the related sub array. eg Rather than RETURN "Capricorn" I want it to RETURN $starsign[0]. What you be the correct syntax to do this so I could later echo the users starsign and details related to that star sign?
  2. I have tried this code and also tried to change somethings but it only ever returns "Capricorn" no matter what date I enter. My HTML is: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Smart Forms JS</title> <script type="text/javascript" src="js/smartform.js"</script> <link rel="stylesheet" href="css/style.css" /> </head> <body> <h2 align="center">What your future holds</h2> <div id="form-area"> <!--<form action="users_details.php" method="post">--> <form action="new.php" method="post"> <fieldset> <legend>Your Personal Details</legend> <p> Please enter your date of birth: <br /> <label for="user_day">Day:<input name="user_day" id="user_day" type="text" size="2" class="reqd" maxlength="2" onkeypress="return isNumberKey(event)"></label> <label for="user_month">Month: <select name="user_month" id="user_month" class="reqd"> <option value="" selected="selected">Choose a month</option> <option value="January">January</option> <option value="February">February</option> <option value="March">March</option> <option value="April">April</option> <option value="May">May</option> <option value="June">June</option> <option value="July">July</option> <option value="August">August</option> <option value="September">September</option> <option value="October">October</option> <option value="November">November</option> <option value="December">December</option> </select> </label> <label for="user_year">Year:<input name="user_year" id="user_year" type="text" size="4" class="reqd" maxlength="4" onkeypress="return isNumberKey(event)" ></label> </p> <p> <input name="submit" type="submit" /> <input name="reset" type="reset" /> </p> </fieldset> </form> </div> </body> </html> and my php is now: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Processed Form</title> <link rel="stylesheet" href="css/style.css" /> </head> <body> <div id="wrapper"> <h2>Processed Form from Birthday Page</h2> <?php //$Capricorn = array("Capricorn", "And so say all of us"); //$Aquarius = array("Aquarius"); //$Pisces = array("Pisces"); //$Aries = array("Aries"); //$Taurus = array("Taurus"); //$Gemini = array("Gemini"); //$Cancer = array("Cancer"); //$Leo = array("Leo"); //$Virgo = array("Virgo"); //$Libra = array("Libra"); //$Scorpio = array("Scorpio"); //$Sagittarius = array("Sagittarius"); //Change variables to multidimentional array: $starsign[0] = array('name'=>'Capricorn', 'description' =>'description of capricorn people'); $starsign[1] = array('name'=>'Aquarius', 'description' =>'description of aquarius people'); $starsign[2] = array('name'=>'Pisces', 'description' =>'description of Pisces people'); $starsign[3] = array('name'=>'Aries', 'description' =>'description of aries people'); $starsign[4] = array('name'=>'Taurus', 'description' =>'description of Taurus people'); $starsign[5] = array('name'=>'Gemini', 'description' =>'description of Gemini people'); $starsign[6] = array('name'=>'Cancer', 'description' =>'description of Cancer people'); $starsign[7] = array('name'=>'Leo', 'description' =>'description of Leo people'); $starsign[8] = array('name'=>'Virgo', 'description' =>'description of Virgo people'); $starsign[9] = array('name'=>'Libra', 'description' =>'description of Libra people'); $starsign[10] = array('name'=>'Scorpio', 'description' =>'description of Scorpio people'); $starsign[11] = array('name'=>'Sagittarius', 'description' =>'description of Sagittarius people'); $month = $_POST['user_month']; $day = $_POST['user_day']; $year = $_POST['user_year']; ?> <?php function star_sign($month, $day, $year) { $time = mktime(0, 0, 0, $month, $day, $year); //return the Unix timestamp $day_of_year = date("z", $time); // "z" is equal to the day of the year 0 to 365 if (date("L", $time) && ($day_of_year > 59)) // for leap years "L" is LEAP YEAR $day_of_year -= 1; // if it is FEB 29 (59) Subtract 1 from the day of year switch ($day_of_year) { case $day_of_year > 356: // above 22nd Dec = Capricorn return "Capricorn"; case $day_of_year > 326: return "Sagittarius"; case $day_of_year > 296: return "Scorpio"; case $day_of_year > 266: return "Libra"; case $day_of_year > 235: return "Virgo"; case $day_of_year > 203: return "Leo"; case $day_of_year > 172: return "Cancer"; case $day_of_year > 140: return "Gemini"; case $day_of_year > 111: return "Taurus"; case $day_of_year > 78: return "Aries"; case $day_of_year > 51: return "Pisces"; case $day_of_year > 20: return "Aquarius"; default: return "Capricorn"; } } echo "Your star sign is " . star_sign($month, $day, $year); ?> I assume that it is only returning the default value in the switch statement? How do I rectify this?
  3. This is so much more logically than my approach flyhoney but I don't understand how to related it back to my form, and WHY I need the year 1985? Is it possible to explain what is happening? I'm a complete PHP novice..... this is the first thing I have ever tried.
  4. Each star sign will hold several pockets of information when I have completed it. $Capricorn = array("<h1>Star NAME", "<p>Star Description " <img>Releated picture") I need to generate a new page on the user's star sign so if someone is Capricorn will have a heading, description and image all relating to Capricorn. That is why I have created an array for each star sign. Is there a better way of doing this?
  5. I have a html form where user enters birthday (day + month) and it is sent to be processed by php to calculate their star sign. Everything works fine but I'm unsure how to treat the data once sent. PHP <?php $Capricorn = array("Capricorn", "The sign Capricorn is one of the most stable and (mostly) serious of the zodiacal types."); $Aquarius = array("Aquarius"); $Pisces = array("Pisces"); $Aries = array("Aries"); $Taurus = array("Taurus"); $Gemini = array("Gemini"); $Cancer = array("Cancer"); $Leo = array("Leo"); $Virgo = array("Virgo"); $Libra = array("Libra"); $Scorpio = array("Scorpio"); $Sagittarius = array("Sagittarius"); ?> <?php $user_month = $_POST['user_month']; $user_day = $_POST['user_day']; echo "Your birthday is {$user_day} of {$user_month} that makes your star sign "; ?> <?php // .........JAN = CAPRICORN or AQUARIUS........ if ( $user_month == "January" ) { if ($user_day <= "19"){ echo "{$Capricorn;[0]}"; } else{ echo "{$Aquarius[0]}"; } } Rather than echo $Capricorn, I want to set this value to be $Capricorn so I can call it later. I have no clue how to go about doing this.
  6. brilliant! thank you very much, you both have help ensure I get to bed tonight.
  7. That works beautifully, thank you. I still a little stuck. If I wanted to control the background-image rather than background-color what would be the correct syntax. I have tried this: //echo "<body style='background-color: ".$_POST['user_color'].";'</body>"; echo "<body style='background-image: url( ".$_POST['user_color'].";.gif)'</body>"; but it doesn't work
  8. Hi all, I'm a complete newbie to PHP and I am having some problems. I need PHP to generate content based on a users input to a HTML form. My first task is to change the background of the page based on the user's favorite color. I can get only one color to work, I don't understand the logic to make each choice represent a different color. Here is what I have: HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Process Color</title> <link rel="stylesheet" href="css/style.css" /> </head> <body> <h2 align="center">Pick A Color</h2> <div id="form-area"> <form action="process_color.php" method="post"> <fieldset> <legend>Your Favorite Color is?</legend> <p> <label for="color">Please Select One:<br /> <select name="user_color" [ ] id="user_color" class="reqd"> <option value="" selected="selected">Choose a colour</option> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Orange">Orange</option> <option value="Green">Green</option> <option value="White">White</option> <option value="Yellow">Yellow</option> <option value="Purple">Purple</option> <option value="Brown">Brown</option> <option value="Black">Black</option> </select> </label> </p> <p> <input name="submit" type="submit" /> <input name="reset" type="reset" /> </p> </fieldset> </form> </div> </body> </html> PHP <?php $user_color = $_POST['user_color']; ?> <?php if ($user_colour = "Red") { echo '<body style="background-color: red;"</body>'; } if ($user_colour = "Blue") { echo '<body style="background-color: blue;"</body>'; } if ($user_colour = "Orange") { echo '<body style="background-color: orange;"</body>'; } if ($user_colour = "Green") { echo '<body style="background-color: green;"</body>'; } if ($user_colour = "White") { echo '<body style="background-color: white;"</body>'; } if ($user_colour = "Yellow") { echo '<body style="background-color: yellow;"</body>'; } if ($user_colour = "Purple") { echo '<body style="background-color: purple;"</body>'; } if ($user_colour = "Brown") { echo '<body style="background-color: brown;"</body>'; } if ($user_colour = "Black") { echo '<body style="background-color: black;"</body>'; } ?> Any help would be greatly appreciated!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.