View Single Post
  #1 (permalink)  
Old 11-03-09, 04:32 AM
swap_ssj swap_ssj is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Problem inserting records...!!!

hi guyes...

i have 2 files, schedulemasternew.php and schedule_entry.php.
here is schedulemasternew.php
PHP Code:

<?php

ob_start
();
session_start();
?>
<?php
        
if($_REQUEST[month]=="January")
        {
            
$maxday=31;
        }
        else if(
$_REQUEST[month]=="February")
        {
            
            
$leap$_REQUEST[year] % 4;
            
            if(
$leap==0)
            {
                
$maxday=29;
            }
            else
            {
                
$maxday=28;
            }
        }
        else if(
$_REQUEST[month]=="March")
        {
            
$maxday=31;
        }
        else if(
$_REQUEST[month]=="April")
        {
            
$maxday=30;
        }
        else if(
$_REQUEST[month]=="May")
        {
            
$maxday=31;
        }
        else if(
$_REQUEST[month]=="June")
        {
            
$maxday=30;
        }
        else if(
$_REQUEST[month]=="July")
        {
            
$maxday=31;
        }
        else if(
$_REQUEST[month]=="August")
        {
            
$maxday=31;
        }
        else if(
$_REQUEST[month]=="September")
        {
            
$maxday=30;
        }
        else if(
$_REQUEST[month]=="October")
        {
            
$maxday=31;
        }
        else if(
$_REQUEST[month]=="November")
        {
            
$maxday=30;
        }
        else if(
$_REQUEST[month]=="December")
        {
            
$maxday=31;
        }
        
session_register("daycount");
        
$_SESSION["daycount"]=$maxday;
    
?>
<table width="757" align="center" cellpadding="0" cellspacing="1"  border="0">
<form name="form" action="schedule_entry.php?action=new" method="post" onsubmit="return validateForms('form');">

    <?php include_once("master_header.php");?>
                                <tr>                            <td align="center" width="100%">
    <table width="80%" align="center" cellpadding="2" cellspacing="1" bgcolor="#333333">
                                <br />                            <tr bgcolor="#FFFFFF">
                                <td colspan="5" align="left" class="bluelink_2"><strong>Water Management</strong></td>
                                </tr>                            <tr bgcolor="#FFFFFF">                        <td width="29%" align="center" class="txtfld12">Date</td>
    <td width="26%" align="center" class="txtfld12">Litres</td>                <td width="26%" align="center" class="txtfld12">Hours</td>
    </tr>                            <?php 
    
for ($i=0;$i<$maxday;$i++)
    {    
    
?>
    <tr bgcolor="#FFFFFF">
                                <td align="center" class="txtfld12" width="8%"><?php echo $i+1 ?></td>
                                <td align="center"><input type="text" name="litres<?php $i?>" id="litres" /><br><span id="litres" class="rederr"></span></td>
    <td align="center"><input type="text" name="hours<?php $i?>" id="hours" /><br><span id="hours" class="rederr"></span></td>
    </tr>
    <?php
    
}
                    
?>
                   <tr bgcolor="#FFFFFF">                            <td colspan="3" align="center" class="txtfld12">&nbsp;</td>
    </tr>
    <tr>                            <td align="center" colspan="3"><input type="submit" class="button" name="Add Schedule" value="Add Schedule" /></td>
    </tr></table></td>
    </tr>
</table>
</form>


And, here is schedule_entry.php

PHP Code:

<?php

ob_start
();
session_start();

include_once(
"conn.php");

$count=$_SESSION["daycount"];

if(
$_GET['action']=="new")
{
    if(
mysql_query("INSERT INTO schedule(plotno,year,month) VALUES('$_POST[plotno]','$_POST[year]','$_POST[month]')"))
    {
    
    
$sid mysql_insert_id();

    
$litres  =$_POST["litres"];
    
$hours  =$_POST["hours"];
    
$record explode('~',$litres);
    
$record1=explode('~',$hours);
    for(
$i=0;$$i<$count;$i++)
    {
        
$ScheduleDetail explode("^",$record[$i]);
        
$ScheduleDetails explode("^",$record1[$i]);
        
$sql ="INSERT INTO scheduledetail(scheduleid,date,litres,hours) values($sid,$i,'$ScheduleDetail[0]','$ScheduleDetails[0]')";
        
mysql_query($sql);
    }
    
    
header("Location:index.php?page=schedulemaster");
}
else {
  echo 
"<br>Query not executed";
}
}
?>
I am creating an application where user selects plot no, year and month. Then according to selected year and month, the no. of days for the selected month are calculated.
and then on next page i.e. schedulemasternew.php, user will have to enter date, litres and hours for no. of times depending upon the month and year selected (i.e. 31 times for January, 28 times for February).
and in schedule_entry.php, there is logic to insert the records.

but, i'm facing problem here while inserting records.
first of all, i'm not sure that, the array is properly created for the records to be inserted.
because, when i execute, it shows Fatal Error :Maximum execution time of 30 seconds exceeded in C:\wamp\www\agro\agro\schedule_entry.php on line 20

and, when i check database, only last entry is inserted in scheduledetail table.

can u please tell me, how should i solve this problem...???
Reply With Quote