My HTML FORM IS:
Code: Select all
<!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>
Code: Select all
<!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?