Please Help me with the Error:Urgent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rahulsinghishere
Forum Newbie
Posts: 4
Joined: Sun Feb 08, 2009 12:42 pm

Please Help me with the Error:Urgent

Post by rahulsinghishere »

Hi,
Sorry to bother you guys but I need some immediate help.

http://www.evienewman.com/duedate/duedate.php
http://www.evienewman.com/ovulation/ovulation.php

On these sites I am getting this message,
document.getElementById('duedatecontainer').innerHTML='

and also the button does not work.

Kindly check for the first link as that is most important.

Following is the code for the first link(http://www.evienewman.com/duedate/duedate.php )

The files are attached along with this message.

I am expecting some help form you guys.
You all are doing a great job of helping other people out.

Please help me out with this.
Attachments
error files.rar
These contain the files which are causing the errors to occur
(5.05 KiB) Downloaded 35 times
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Please Help me with the Error:Urgent

Post by John Cartwright »

Firstly, your urgency is not ours, and since we are all volunteers here I will ask you to keep that you yourself please.

As for your first the reason you are getting the document innerhtml text is because you have not encapsulated your javascript in <script></script> tags. Secondly, your javascript will attempt to replace the inner content of a element (probably a div) that doesn't exist (since that script is the only thing on the page). You need to place this code (in script tags), on the page that has the associated element's id.

I.e.,

Code: Select all

 
<script language="javascript" type="text/javascript">
    //all your javascript
</script>
 
<div id="ovulationcontainer"></div>
rahulsinghishere
Forum Newbie
Posts: 4
Joined: Sun Feb 08, 2009 12:42 pm

Re: Please Help me with the Error:Urgent

Post by rahulsinghishere »

Hi,
I did that but still it is giving me that error.



The probs I suppose is that the data in $content has single quotes which breaks the code.

Now, I have a div with an id and I have placed the script tags too.

Thanks for your help but I may need some more of it.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Please Help me with the Error:Urgent

Post by watson516 »

I took a quick look at that first link you posted and you get that first problem (the printing of the javascript) because, as stated previously, you have no script tags. As for the button not working, this is also because you have no script tags. Your submit button is of the type=button meaning, just by itself, it does nothing. You have an onclick on the button which would do something IF you had the javascript function that is being called somewhere on the page.

You need either an external javascript file or internal. Either way, you need script tags.

EDIT
You didn't post any code so you probably shouldn't refer to stuff in your code and expect help

EDIT
use [ code=php]...[ /code] to post code on the forums. Don't upload files. No one is going to download them to help you.
rahulsinghishere
Forum Newbie
Posts: 4
Joined: Sun Feb 08, 2009 12:42 pm

Re: Please Help me with the Error:Urgent

Post by rahulsinghishere »

Hi,

I have attached the files with the first post.

right now I am looking for solution for duedate.php file and the attachment has all the files required
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Please Help me with the Error:Urgent

Post by watson516 »

rahulsinghishere wrote:Hi,

I have attached the files with the first post.

right now I am looking for solution for duedate.php file and the attachment has all the files required
How about posting that code (not files) to this thread?
rahulsinghishere
Forum Newbie
Posts: 4
Joined: Sun Feb 08, 2009 12:42 pm

Re: Please Help me with the Error:Urgent

Post by rahulsinghishere »

Hi,
OK I have done one part correctly ,
Now, the problem is when i click on the calculate button it does not work , some problem with the onClick attribute of the button ,

Kindly Help me with this ,
Ok I will Post the code here

////The page duedate.php

Code: Select all

 
<?php
require_once( './config.php' );
 
function safe_get_string($param, $default) {
    if (array_key_exists($param, $_GET)) {
        if (!get_magic_quotes_gpc()) {
            return addslashes($_GET[$param]);
        }
        else {
            return $_GET[$param];
        }
    }
    else {
        return $default;
    }
}
 
function safe_get_integer($param, $default) {
    if (array_key_exists($param, $_GET)) {
        return (int) $_GET[$param];
    }
    else {
        return $default;
    }
}
 
$action = safe_get_string( 'action', '' );
 
ob_start();
 
if ( $action == '' ) {
?>
 
<table width="483" height="286" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="3"><img style="vertical-align: bottom;" src="<?php echo $main_path; ?>images/duedatenew.gif" width="483" height="34" alt=""></td>
    </tr>
    <tr>
        <td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_02.jpg" width="11" height="252" alt=""></td>
        <td valign="TOP">
            <div style="padding: 12px; font-family: arial; font-size: 10pt; color: #333333;">
                <span style="color: #669900; font-size: 14pt; font-weight: bold; font-family: times;">&nbsp;Due Date Calculator</span>
                <p style="margin-bottom: 0px; margin-top: 8px;">
                    Not sure when your baby is due? Our handy calculator will help predict your most likely due date.
                </p>
                <p style="margin-bottom: 0px; margin-top: 8px;">
                    <strong>What was the date of first day of your last period?</strong>
                    <br />
                    <input type="TEXT" size="12" id="lastperiod" name="lastperiod">
                    &nbsp;
                    <input type="button" onclick="displayDatePicker('lastperiod');" value="select"/>
                </p>
                <p style="margin-bottom: 0px; margin-top: 8px;">
                    <strong>Adjusted cycle length:</strong>&nbsp;If you know that your cycle is shorter or longer than 28 days, please adjust the number below.
                    <br />
                    <select id="cyclelength">
                        <option value="21">21 days</option>
                        <option value="22">22 days</option>
                        <option value="23">23 days</option>
                        <option value="24">24 days</option>
                        <option value="25">25 days</option>
                        <option value="26">26 days</option>
                        <option value="27">27 days</option>
                        <option value="28" SELECTED>28 days</option>
                        <option value="29">29 days</option>
                        <option value="30">30 days</option>
                        <option value="31">31 days</option>
                        <option value="32">32 days</option>
                        <option value="33">33 days</option>
                        <option value="34">34 days</option>
                        <option value="35">35 days</option>
                        <option value="36">36 days</option>
                        <option value="37">37 days</option>
                    </select>
                </p>
                <p align="RIGHT" style="margin-bottom: 0px; margin-top: 8px;">
                   [b] <input type="button"  onclick="ajaxFunction('action=calculate&lastperiod='+document.getElementById('lastperiod').value+'&cyclelength='+document.getElementById('cyclelength').value);">Calculate my due date</button>[/b]
                </p>
            </div>
        </td>
        <td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_04.jpg" width="10" height="252" alt=""></td>
    </tr>
    <tr>
        <td><img src="<?php echo $main_path; ?>images/main_05.jpg" width="462" height="12" alt=""></td>
    </tr>
</table>
 
<?php
}
elseif ( $action == 'calculate' ) {
 
    $lastperiod2 = safe_get_string( 'lastperiod', date( 'd/m/Y' ) );
    $lastperiodexpl = explode('/',$lastperiod2);
 
    $lastperiod = $lastperiodexpl[1] . "/" .  $lastperiodexpl[0] . "/" . $lastperiodexpl[2];
    $cyclelength = safe_get_integer( 'cyclelength', 28 );
 
    $from_date_raw = @strtotime( $lastperiod );
    $from_date = getdate( $from_date_raw );
 
    $this_date_raw = time();
    $this_date = getdate( $this_date_raw );
 
    $from_year = $from_date['year'];
    $this_year = $this_date['year'];
 
    $days = date( 'z', $this_date_raw );
 
    while ( $from_year < $this_year ) {
        $days = $days + 365 + date( 'L', mktime( 0, 0, 0, 12, 31, $from_year ) );
        $from_year++;
    }
 
    $days -= date( 'z', $from_date_raw );
    $weeks = -1;
    $days_remaining = -1;
    
    if ( $days >= 0 ) {
        $weeks = floor( $days/7 );
        
        $est_date_raw = mktime( 0, 0, 0, $from_date['mon'], $from_date['mday'] + 280, $from_date['year'] );
        $est_date = getdate( $est_date_raw );
        
        $days_remaining = 280 - $days;
        if ( $days_remaining >= 0 ) {
            $weeks_remaining = floor( $days_remaining/7 );
            $days_remaining_2 = $days_remaining % 7;
        }
    }
    
    if ( $days >= 0 ) {
        if ( $weeks < 42 ) {
            if ( ( $weeks % 10 ) != 1 ) {
                $firstline = "You are $weeks weeks pregnant.";
            }
            else {
                $firstline = "You are $weeks week pregnant.";
            }
            if ( $days_remaining > 0 ) {
                $firstline .= " You are due on " . date( 'd/m/y', $est_date_raw ) . '.';
            }
        }
        else {
            $firstline = "You are not pregnant or already gave birth.";
        }
    }
    else {
        $firstline = "You are not pregnant. Not yet.";
    }
    
    $secondline = '';
    if ( $days_remaining > 0 ) {
 
        $secondline = 'You have';
 
        if ( $weeks_remaining > 0 ) {
            if ( ( $weeks_remaining % 10 ) != 1 ) {
                $secondline .= " $weeks_remaining weeks";
            }
            else {
                $secondline .= " $weeks_remaining week";
            }
        }
        else {
            $secondline .= " only";
        }
        
        if ( $days_remaining_2 > 0 ) {
            if ( ( $days_remaining_2 % 10 ) != 1 ) {
                $secondline .= " $days_remaining_2 days";
            }
            else {
                $secondline .= " $days_remaining_2 day";
            }
        }
        
        $secondline .= " left.";
    }
    
    $show_text = false;
    if ( ( $weeks >= 0 ) && ( $weeks <= 41 ) ) {
        $show_text = true;
    }
    
?>
 
<table width="483" height="286" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="3"><img style="vertical-align: bottom;" src="<?php echo $main_path; ?>images/main_01.jpg" width="483" height="34" alt=""></td>
    </tr>
    <tr>
        <td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_02.jpg" width="11" height="252" alt=""></td>
        <td valign="TOP" height="240">
            <div style="padding: 12px; font-family: times; font-size: 12pt; color: #669900;">
                <span style="color: #669900; font-size: 14pt; font-weight: bold; font-family: times;">&nbsp;Your Calculated Due Date</span>
                <p style="margin-bottom: 0px; margin-top: 8px;">
                    <?php echo $firstline; ?>
                </p>
<?php
    if ( $secondline != '' ) {
?>
                <p style="margin-bottom: 0px; margin-top: 8px;">
                    <?php echo $secondline; ?>
                </p>
<?php
    }
    if ( $show_text ) {
?>
                <p style="margin-bottom: 0px; margin-top: 8px;">
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td valign="TOP"><img src="<?php echo $main_path; ?>images/weeks/<?php echo $__weeks_pictures[$weeks]; ?>"></td>
                            <td>&nbsp;&nbsp;</td>
                            <td valign="TOP">
                                <span style="color: #333333; font-size: 14pt; font-weight: bold; font-family: times;">Week <?php echo ( $weeks + 1 ); /* if ( ( $weeks + 1 ) % 10 == 1 ) { echo 'st'; } elseif ( ( $weeks + 1 ) % 10 == 2 ) { echo 'nd'; } elseif ( ( $weeks + 1 ) % 10 == 3 ) { echo 'rd'; } else { echo 'th'; }*/ ?></span>
                                <br />
                                <span style="color: #333333; font-size: 8pt; font-family: arial;"><?php echo $__weeks_data[$weeks]; ?></span>
                            </td>
                        </tr>
                    </table>
                </p>
<?php
    }
?>
            </div>
        </td>
        <td rowspan="2" valign="TOP"><img src="<?php echo $main_path; ?>images/main_04.jpg" width="10" height="252" alt=""></td>
    </tr>
    <tr>
        <td valign="TOP"><img src="<?php echo $main_path; ?>images/main_05.jpg" width="462" height="12" alt=""></td>
    </tr>
</table>
 
<?php
    
}
 
$content = ob_get_contents();
ob_end_clean();
 
$content = str_replace( array( "\r\n", "\n" ), "", $content );
$content = str_replace( "'", "'+\"'\"+'", $content ); //"
 
echo "document.getElementById('duedatecontainer').innerHTML='$content';";
?>
 
 
//duedate.js file with the AjaxFunction

var main_path = "http://www.bumples.co.uk/duedate/";

function ajaxFunction(req)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
if ( xmlHttp.responseText != '' ) {
eval( xmlHttp.responseText );
}
}
}

xmlHttp.open("GET",main_path+"duedate.php?"+req,true);
xmlHttp.send(null);
}
Last edited by rahulsinghishere on Sun Feb 08, 2009 3:38 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Please Help me with the Error:Urgent

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Post Reply