Page 1 of 1

mysql_query syntax error... i cant find it

Posted: Wed Jun 03, 2009 1:50 am
by rbroadwe

Code: Select all

    
  <?php 
//mysql connect
$con = mysql_connect("localhost","robbroa1_dbuser","GKk&HRVb|fx(");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
//open db
mysql_select_db("robbroa1_fox", $con);
 
//pull input variables
$month = $_POST["month"];
$year  = $_POST["year"];
$pw    = $_POST["pw"];
 
//capture days in the month
$date = mktime(0,0,0, $month, 1, $year);
$days_in_month = date('t', $date);
 
//global counting vars
$day_count = 1;
$times_count = 1;
 
while( $day_count <= $days_in_month && $pw == 'success')
{
    // time for current counter day
    $fill_day = mktime(0,0,0, $month, $day_count, $year);
    
    $fill_day_of_week = date('w', $fill_day);
    
    // 0 is Sunday
    // 1 is Monday
    // 2 is Tuesday
    // 3 is Wednesday
    // 4 is Thursday
    // 5 is Friday
    // 6 is Saturday
    
    if( $fill_day_of_week == 0 )
    {
        $times[0]="12:00";
        $times[1]="02:00";
        $times[2]="04:00";
        $times[3]="06:00"; 
        $number_of_times = "4";
    }
    else if( $fill_day_of_week == 1 )
    {
        $times[0]="12:00";
        $times[1]="02:00";
        $times[2]="04:00";
        $times[3]="06:00"; 
        $number_of_times = "4";
    }
    else if( $fill_day_of_week == 2 )
    {
        $times[0]="12:00";
        $times[1]="02:00";
        $times[2]="04:00";
        $times[3]="06:00";  
        $number_of_times = "4";
    }
    else if( $fill_day_of_week == 3 )
    {
        $times[0]="12:00";
        $number_of_times = "1";     
    }
    else if( $fill_day_of_week == 4 )
    {
        $times[0]="06:00";
        $number_of_times = "1"; 
    }
    else if( $fill_day_of_week == 5 )
    {
        $times[0]="06:00";
        $number_of_times = "1"; 
    }
    else if( $fill_day_of_week == 6 )
    {
        $times[0]="12:00";
        $times[1]="02:00";
        $times[2]="04:00";
        $times[3]="06:00";  
        $number_of_times = "4";
    }
    
    while( $times_count <= $number_of_times )
    {   
        
        $value = $times[$times_count];
        $retval = mysql_query("
                            INSERT INTO appt (month, day, year, time, ampm)
                            VALUES ('$month', '$day', $year', '$value', 'PM')
                            ");
        if(! $retval )
        {
            die('Could not update data: ' . mysql_error());
        }
        $times_count++;
        
    }
    
    //increment
    $day_count++;
    $times_count = 1;
    
}
?>
 
throws
Could not update data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', '02:00', 'PM')' at line 2
Any help would be greatly appreciated.

Cheers

Re: mysql_query syntax error... i cant find it

Posted: Wed Jun 03, 2009 2:12 am
by anand
try this in line 99

Code: Select all

 
        $retval = mysql_query("
                            INSERT INTO appt (month, day, year, time, ampm)
                            VALUES ('$month', '$day', $year', '$value', 'PM');
                            ");
 
P.S. I have added a semicolon in the query [ after "PM )" ]

Why did you edit the previous code? :dubious: :dubious: :dubious:

anyways, I guess this is the final time you have edited your post. So, here it is

Code: Select all

 
        mysql_query("
            INSERT INTO appt (month, day, year, time, ampm)
            VALUES ('$month', '$day', $year', $value', 'PM');")
 
Try this.

Re: mysql_query syntax error... i cant find it

Posted: Wed Jun 03, 2009 2:19 am
by anand
You have edited your codes again 8O 8O 8O 8O 8O 8O 8O 8O 8O

Re: mysql_query syntax error... i cant find it

Posted: Wed Jun 03, 2009 2:19 am
by rbroadwe
sorry I was trying different ways and was adapting it as I changed it... i edited it back to the original.

So I've tried foreach and using a pointer $times[$times_count]...