I have a due date calculator on my site coded in php. http://www.babytalkzone.com/duedatecalculator/ It has worked fine for a long time until I got a new server. I moved my site over with cpanel, and this seems to be the only problem. It may be due to php being upgraded. I looked at the code to see if there was anything wrong that I could tell and didn't see anything, but I am not a coder. I suspect the underlying version of php changed and either some function changed the way it works, or else some word that was not reserved in php4 is now reserved in php5. Thanks for any help you can give.
check for this functions.. str_pos, strlen or str_len This are the some php 4 functions that i know that are reformatted in php 5.
I think the problem is not the php version, but the setting of the php. For example your new host doesn't have register_globals turn on.
Thanks! I'll get register_globals turned on and see if that fixes it and also check for str_len, strlen, and str_pos. If that doesn't fix it, yes, I have the code. It is across a few files, and it is also built into vbulletin templates.
I tried turning register_globals on and it had no effect. There is no strlen, str_len, or str_pos in the code. Here is some of the pertinent code. variables on initial page: $next_year = date("Y") + 1; $this_year = date("Y"); $last_year = date("Y") - 1; Code (markup): Form to fill out: <form name="myForm" method="post" action="calculate_date.php"> <label> First Day of Last Menstural Cycle: <select name="month" onChange="populateDays(this)"> <option value="">Month</option> <option value="0">January</option> <option value="1">February</option> <option value="2">March</option> <option value="3">April</option> <option value="4">May</option> <option value="5">June</option> <option value="6">July</option> <option value="7">August</option> <option value="8">September</option> <option value="9">October</option> <option value="10">November</option> <option value="11">December</option> </select> <select name="day"> <option value="">Day</option> </select> <select name="year"> <option value="">Year</option> <option>$next_year</option> <option>$this_year</option> <option>$last_year</option> </select> </label><br /><br /> <label> Length of your cycle (e.g. 28 days, etc.): <input type="text" name="cycle_length" value="28" size="3" length="3" />days </label><br /><br /> <label> <fieldset> <legend>Due Date Calculation Method</legend><br /> <input type="radio" name="calc_mthd" value="1" CHECKED />Add 40 Weeks (or 280 Days)<br /><br /> <input type="radio" name="calc_mthd" value="3" />Count Back 3 Months, add 1 year and 7 days<br /> </fieldset> </label><br /><br /> <center><label> <input type="submit" value="Get Due Date" /> </label></center> </form> Code (markup): Calculations: // ## this calls to print out the DueDateCalculator template ## if ($due_date == '') { // $month += 1; if ($cycle_length > 28) { $total_length = ($cycle_length - 28); $day = $day + $total_length; } else if ($cycle_length == 28) { $total_length = 28; } else { $total_length = 28 - $cycle_length; $day = $day - $total_length; } if ($method == 3) { $due_date = date("F jS, Y", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_month = date("m", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_day = date("d", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_year = date("Y", mktime(0,0,0, $month-3, $day+7, $year+1)); } else { $due_date = date("F jS, Y", mktime(0,0,0,$month, $day+280, $year)); $due_month = date("m", mktime(0,0,0,$month, $day+280, $year)); $due_day = date("d", mktime(0,0,0,$month, $day+280, $year)); $due_year = date("Y", mktime(0,0,0,$month, $day+280, $year)); } } $conception_date = date("F jS, Y", mktime(0,0,0,$month, $day+14, $year)); $day_of_week = date("l", mktime(0,0,0, $due_month, $due_day, $due_year)); $link = mysql_connect('localhost','btz','tinuviel99'); mysql_select_db('btz_vbforum'); $sql = "SELECT * FROM ddc_birthstone WHERE id='".$due_month."' LIMIT 1"; $results = mysql_query($sql, $link); $x = mysql_fetch_object($results); $birthflower = $x->flower; $birthstone = $x->stone; switch($due_month) { case 1: $dcc_m = "dcc_january"; if ($due_day >= 21) { $zodiac = "Aquarius"; } else { $zodiac = "Capricorn"; } break; case 2: $dcc_m = "dcc_february"; if ($due_day >= 21) { $zodiac = "Pisces"; } else { $zodiac = "Aquarius"; } break; case 3: $dcc_m = "dcc_march"; if ($due_day >= 22) { $zodiac = "Aries"; } else { $zodiac = "Pisces"; } break; case 4: $dcc_m = "dcc_april"; if ($due_day >= 21) { $zodiac = "Taurus"; } else { $zodiac = "Aries"; } break; case 5: $dcc_m = "dcc_may"; if ($due_day >= 22) { $zodiac = "Gemini"; } else { $zodiac = "Taurus"; } break; case 6: $dcc_m = "dcc_june"; if ($due_day >= 22) { $zodiac = "Cancer"; } else { $zodiac = "Gemini"; } break; case 7: $dcc_m = "dcc_july"; if ($due_day >= 23) { $zodiac = "Leo"; } else { $zodiac = "Cancer"; } break; case 8: $dcc_m = "dcc_august"; if ($due_day >= 23) { $zodiac = "Virgo"; } else { $zodiac = "Leo"; } break; case 9: $dcc_m = "dcc_september"; if ($due_day >= 23) { $zodiac = "Libra"; } else { $zodiac = "Virgo"; } break; case 10: $dcc_m = "dcc_october"; if ($due_day >= 24) { $zodiac = "Scorpio"; } else { $zodiac = "Libra"; } break; case 11: $dcc_m = "dcc_november"; if ($due_day >= 22) { $zodiac = "Sagittarius"; } else { $zodiac = "Scorpio"; } break; case 12: $dcc_m = "dcc_december"; if ($due_day >= 22) { $zodiac = "Capricorn"; } else { $zodiac = "Sagittarius"; } break; } // $sql = "SELECT * FROM ". $dcc_m ." WHERE day= '".$day."'"; $sql = "SELECT * FROM ". $dcc_m ." WHERE day= '".$due_day."'"; $results = mysql_query($sql, $link); $y = mysql_fetch_object($results); $famous_names = $y->names; Code (markup): Form results here: <h1>Congratulations on your pregnancy!</h1> <br /> <h2>Your baby is due on $day_of_week, $due_date</h2> <br /><br /> <h3>Your baby's estimated conception date is $conception_date Code (markup):
You're using POST method, but in your calculate_date.php using only global variable, that doesn't work if you don't have register_globals turn on. Since you said register_globals already on but it's still doesn't work, you may wanna try this: in your calculate_date.php Change: Change all $cycle_length to $_POST['cycle_length'] Change all $month to $_POST['month'] Change all $day to $_POST['day'] Change all $year to $_POST['year'] Change all $calc_mthd to $_POST['calc_mthd']
I found this at the top, and it looks like I should have included it in the previous post. I think it does what you are saying. $due_date = ''; $month = ($_POST['month']) + 1; $day = $_POST['day']; $year = $_POST['year']; $cycle_length = $_POST['cycle_length']; $method = $_POST['calc_mthd']; Code (markup):
Just in case anything else is needed, here's the full code on the page <?php $due_date = ''; $month = ($_POST['month']) + 1; $day = $_POST['day']; $year = $_POST['year']; $cycle_length = $_POST['cycle_length']; $method = $_POST['calc_mthd']; /* if ($cycle_length > 28) { $total_length = ($cycle_length - 28); $day = $day - $total_length; } else if ($cycle_length == 28) { $total_length = 28; } else { $total_length = 28 - $cycle_length; $day = $day + $total_length; } if ($method == 1) { $due_date = date("m-d-Y", mktime(0,0,0,$month, $day+280, $year)); } else if ($method == 2) { $due_date = date("m-d-Y", mktime(0,0,0,$month, $day+280, $year)); } else { $due_date = date("m-d-Y", mktime(0,0,0,$month-3, $day+7, $year+1)); } */ // ## Changes Directory so it can accesss vBulletin IF we are outside the forums folder, if not this is not nessary ## chdir("/home/btz/public_html/forums"); // ## Error Reporting ( we use error reporting in php so we can control the display of error messages // ## we will use this because all vBulletin files follow the same error reporting rules) ## error_reporting(E_ALL & ~E_NOTICE); // ## this here defines the "this_script" function, which if you use template conditionals, it will come in handy :) ## define('THIS_SCRIPT', 'ddc'); // ## this action here cache's the templates so that everytime their needed a querry wont be needed to run // ## the names in there are just the template names :), there must be a comma after everyone but the last ## $globaltemplates = array( 'header', 'navbar', 'footer', 'ddc_calculate' ); // ## Grabs global.php this grabs vbulletins global.php so we can use the most basic of vBulletins functions ## $specialtemplates = array( 'smiliecache', 'bbcodecache' ); // pre-cache templates used by specific actions $actiontemplates = array(); // ########################## REQUIRE BACK-END ############################ require_once("/home/btz/public_html/forums/global.php"); // #################### HARD CODE JAVASCRIPT PATHS ######################## $headinclude = str_replace('"clientscript', '"' . $vbulletin->options['bburl'] . '/clientscript', $headinclude); // ######################################################################## // ######################### START MAIN SCRIPT ############################ // ######################################################################## $navbits = array(); // change the line below to contain whatever you want to show in the navbar (title of your custom page) $navbits[$parent] = 'Due Date Calculator Results'; $navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";'); // ## ok this next set of lines "eval"'s our templates so they can be called inside the template we will print out ## eval('$header = "' . fetch_template('header') . '";'); eval('$navbar = "' . fetch_template('navbar') . '";'); eval('$footer = "' . fetch_template('footer') . '";'); // ## this calls to print out the DueDateCalculator template ## if ($due_date == '') { // $month += 1; if ($cycle_length > 28) { $total_length = ($cycle_length - 28); $day = $day + $total_length; } else if ($cycle_length == 28) { $total_length = 28; } else { $total_length = 28 - $cycle_length; $day = $day - $total_length; } if ($method == 3) { $due_date = date("F jS, Y", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_month = date("m", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_day = date("d", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_year = date("Y", mktime(0,0,0, $month-3, $day+7, $year+1)); } else { $due_date = date("F jS, Y", mktime(0,0,0,$month, $day+280, $year)); $due_month = date("m", mktime(0,0,0,$month, $day+280, $year)); $due_day = date("d", mktime(0,0,0,$month, $day+280, $year)); $due_year = date("Y", mktime(0,0,0,$month, $day+280, $year)); } } $conception_date = date("F jS, Y", mktime(0,0,0,$month, $day+14, $year)); $day_of_week = date("l", mktime(0,0,0, $due_month, $due_day, $due_year)); $link = mysql_connect('localhost','btz','tinuviel99'); mysql_select_db('btz_vbforum'); $sql = "SELECT * FROM ddc_birthstone WHERE id='".$due_month."' LIMIT 1"; $results = mysql_query($sql, $link); $x = mysql_fetch_object($results); $birthflower = $x->flower; $birthstone = $x->stone; switch($due_month) { case 1: $dcc_m = "dcc_january"; if ($due_day >= 21) { $zodiac = "Aquarius"; } else { $zodiac = "Capricorn"; } break; case 2: $dcc_m = "dcc_february"; if ($due_day >= 21) { $zodiac = "Pisces"; } else { $zodiac = "Aquarius"; } break; case 3: $dcc_m = "dcc_march"; if ($due_day >= 22) { $zodiac = "Aries"; } else { $zodiac = "Pisces"; } break; case 4: $dcc_m = "dcc_april"; if ($due_day >= 21) { $zodiac = "Taurus"; } else { $zodiac = "Aries"; } break; case 5: $dcc_m = "dcc_may"; if ($due_day >= 22) { $zodiac = "Gemini"; } else { $zodiac = "Taurus"; } break; case 6: $dcc_m = "dcc_june"; if ($due_day >= 22) { $zodiac = "Cancer"; } else { $zodiac = "Gemini"; } break; case 7: $dcc_m = "dcc_july"; if ($due_day >= 23) { $zodiac = "Leo"; } else { $zodiac = "Cancer"; } break; case 8: $dcc_m = "dcc_august"; if ($due_day >= 23) { $zodiac = "Virgo"; } else { $zodiac = "Leo"; } break; case 9: $dcc_m = "dcc_september"; if ($due_day >= 23) { $zodiac = "Libra"; } else { $zodiac = "Virgo"; } break; case 10: $dcc_m = "dcc_october"; if ($due_day >= 24) { $zodiac = "Scorpio"; } else { $zodiac = "Libra"; } break; case 11: $dcc_m = "dcc_november"; if ($due_day >= 22) { $zodiac = "Sagittarius"; } else { $zodiac = "Scorpio"; } break; case 12: $dcc_m = "dcc_december"; if ($due_day >= 22) { $zodiac = "Capricorn"; } else { $zodiac = "Sagittarius"; } break; } // $sql = "SELECT * FROM ". $dcc_m ." WHERE day= '".$day."'"; $sql = "SELECT * FROM ". $dcc_m ." WHERE day= '".$due_day."'"; $results = mysql_query($sql, $link); $y = mysql_fetch_object($results); $famous_names = $y->names; $userid = ''; /* if ($bbuserinfo['userid']) { $userid = $bbuserinfo['userid']; $sql = "UPDATE btzvb_userfield SET field5='".$due_date."' WHERE userid = '". $userid ."' LIMIT 1"; $results = mysql_query($sql, $link); } */ eval('print_output("' . fetch_template('ddc_calculate') . '");'); ?> Code (markup):
Hmm, I think this part is part of the script to make it works. But for some reason its being comment out. /* if ($cycle_length > 28) { $total_length = ($cycle_length - 28); $day = $day - $total_length; } else if ($cycle_length == 28) { $total_length = 28; } else { $total_length = 28 - $cycle_length; $day = $day + $total_length; } if ($method == 1) { $due_date = date("m-d-Y", mktime(0,0,0,$month, $day+280, $year)); } else if ($method == 2) { $due_date = date("m-d-Y", mktime(0,0,0,$month, $day+280, $year)); } else { $due_date = date("m-d-Y", mktime(0,0,0,$month-3, $day+7, $year+1)); } */ PHP: Just remove the top /* and the bottom */ then try again.
I believe that is the original way the programmer was doing the calculations, but he changed it. I think it is commented out just to preserve it for reference. The $due_date is calculated further down. I will try uncommenting that code and see if it makes a difference, but the code that is there was working fine until I changed servers. I really appreciate you taking time to look at this. I just don't know enough to be able to tell what it is. I really thought the register globals thing was going to do it. Are there other php settings that could be the problem?
Interesting... It did fix the due date calculation. The conception date is still wrong, and it broke the rest of the things that were working such as birth flower and celebrities born on your birthday.
I try your code without the database part, and it works just fine. copy and save this as test.php file then upload to your host and try it. <?php if($_POST['day']) { $due_date = ''; $month = ($_POST['month']) + 1; $day = $_POST['day']; $year = $_POST['year']; $cycle_length = $_POST['cycle_length']; $method = $_POST['calc_mthd']; if ($cycle_length > 28) { $total_length = ($cycle_length - 28); $day = $day - $total_length; } else if ($cycle_length == 28) { $total_length = 28; } else { $total_length = 28 - $cycle_length; $day = $day + $total_length; } if ($method == 1) { $due_date = date("m-d-Y", mktime(0,0,0,$month, $day+280, $year)); } else if ($method == 2) { $due_date = date("m-d-Y", mktime(0,0,0,$month, $day+280, $year)); } else { $due_date = date("m-d-Y", mktime(0,0,0,$month-3, $day+7, $year+1)); } // ## this calls to print out the DueDateCalculator template ## if ($due_date == '') { // $month += 1; if ($cycle_length > 28) { $total_length = ($cycle_length - 28); $day = $day + $total_length; } else if ($cycle_length == 28) { $total_length = 28; } else { $total_length = 28 - $cycle_length; $day = $day - $total_length; } if ($method == 3) { $due_date = date("F jS, Y", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_month = date("m", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_day = date("d", mktime(0,0,0, $month-3, $day+7, $year+1)); $due_year = date("Y", mktime(0,0,0, $month-3, $day+7, $year+1)); } else { $due_date = date("F jS, Y", mktime(0,0,0,$month, $day+280, $year)); $due_month = date("m", mktime(0,0,0,$month, $day+280, $year)); $due_day = date("d", mktime(0,0,0,$month, $day+280, $year)); $due_year = date("Y", mktime(0,0,0,$month, $day+280, $year)); } } $conception_date = date("F jS, Y", mktime(0,0,0,$month, $day+14, $year)); $day_of_week = date("l", mktime(0,0,0, $due_month, $due_day, $due_year)); switch($due_month) { case 1: $dcc_m = "dcc_january"; if ($due_day >= 21) { $zodiac = "Aquarius"; } else { $zodiac = "Capricorn"; } break; case 2: $dcc_m = "dcc_february"; if ($due_day >= 21) { $zodiac = "Pisces"; } else { $zodiac = "Aquarius"; } break; case 3: $dcc_m = "dcc_march"; if ($due_day >= 22) { $zodiac = "Aries"; } else { $zodiac = "Pisces"; } break; case 4: $dcc_m = "dcc_april"; if ($due_day >= 21) { $zodiac = "Taurus"; } else { $zodiac = "Aries"; } break; case 5: $dcc_m = "dcc_may"; if ($due_day >= 22) { $zodiac = "Gemini"; } else { $zodiac = "Taurus"; } break; case 6: $dcc_m = "dcc_june"; if ($due_day >= 22) { $zodiac = "Cancer"; } else { $zodiac = "Gemini"; } break; case 7: $dcc_m = "dcc_july"; if ($due_day >= 23) { $zodiac = "Leo"; } else { $zodiac = "Cancer"; } break; case 8: $dcc_m = "dcc_august"; if ($due_day >= 23) { $zodiac = "Virgo"; } else { $zodiac = "Leo"; } break; case 9: $dcc_m = "dcc_september"; if ($due_day >= 23) { $zodiac = "Libra"; } else { $zodiac = "Virgo"; } break; case 10: $dcc_m = "dcc_october"; if ($due_day >= 24) { $zodiac = "Scorpio"; } else { $zodiac = "Libra"; } break; case 11: $dcc_m = "dcc_november"; if ($due_day >= 22) { $zodiac = "Sagittarius"; } else { $zodiac = "Scorpio"; } break; case 12: $dcc_m = "dcc_december"; if ($due_day >= 22) { $zodiac = "Capricorn"; } else { $zodiac = "Sagittarius"; } break; } echo "<h1>Congratulations on your pregnancy!</h1> <br /> <h2>Your baby is due on $day_of_week, $due_date</h2> <br /><br /> <h3>Your baby's estimated conception date is $conception_date"; } ?> <form name="myForm" method="post" action="test.php"> <label> First Day of Last Menstural Cycle: <select name="month" onChange="populateDays(this)"> <option value="">Month</option> <option value="0">January</option> <option value="1">February</option> <option value="2">March</option> <option value="3">April</option> <option value="4">May</option> <option value="5">June</option> <option value="6">July</option> <option value="7">August</option> <option value="8">September</option> <option value="9">October</option> <option value="10">November</option> <option value="11">December</option> </select> <select name="day"> <option value="">Day</option> <script>for(var i=1;i<32;i++) {document.write("<option value='"+i+"'>"+i+"</option>")};</script> </select> <select name="year"> <option value="">Year</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> </select> </label><br /><br /> <label> Length of your cycle (e.g. 28 days, etc.): <input type="text" name="cycle_length" value="28" size="3" length="3" />days </label><br /><br /> <label> <fieldset> <legend>Due Date Calculation Method</legend><br /> <input type="radio" name="calc_mthd" value="1" CHECKED />Add 40 Weeks (or 280 Days)<br /><br /> <input type="radio" name="calc_mthd" value="3" />Count Back 3 Months, add 1 year and 7 days<br /> </fieldset> </label><br /><br /> <center><label> <input type="submit" value="Get Due Date" /> </label></center> </form> PHP: Edit: check your mysql info. When I try it on your site I get the following Warning on the top of your page. Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/btz/public_html/duedatecalculator/calculate_date.php on line 263 Code (markup):
That came back with correct info. I put the comments back in on the calculate_date.php, and the sql results returned fine. Of course, the original problem of the due date and estimated conception date being wrong came back. This is very close! The date calculations work in your test.php, and the sql works in the calculate_date.php.