It wont insert into table? :S

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
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

It wont insert into table? :S

Post by oscardog »

Here is the code, thanks for uh i think it was mickey for the code :)

Code: Select all

if(isset($_POST['submit'])) {
 
for($itime=1; $itime<=23; $itime++){
     $entry = $_POST[$itime];
     if(isset($_POST[$itime])){
          $resultplanner= mysql_query("SELECT event FROM plannerentries WHERE userid = '".$user_id."' AND day = '".$day."' AND month = '".$month."' AND time = '".$itime."' AND year = '".$year."'") or die(mysql_error());
            $rowplanner = mysql_fetch_array($resultplanner);
            $currententry = $rowplanner['event'];
            $currententrytest = strlen($currententry);
            if($currententrytest == 0) {
            $entry = addslashes($_POST['$entry']);
            mysql_query("INSERT INTO plannerentries (userid, day, month, year, time, event) VALUES ('".$user_id."', '".$day."', '".$month."' , '".$year."', '".$itime."' '".$entry."')");
            echo "You successfully submited your planner entries for the" . $day . "/" . $month . "/" . $year . "<a href=\"edit_planner_check.php\">Click here</a> to add/edit another entry";
            }
            else
            {
            $entry = addslashes($_POST['$itime']);
            mysql_query("UPDATE plannerentries SET event = '".$entry."' WHERE userid = '".$user_id."' AND day = '".$day."' AND month = '".$month."' AND time = '".$itime."' AND year = '".$year."'");
            echo "You successfully updated your planner entries for the" . $day . "/" . $month . "/" . $year . "<a href=\"edit_planner_check.php\">Click here</a> to add/edit another entry";
            } 
            
     }
}
Now the textfields are named '1' '2' '3' '4' etc and refer to a time of the day. So each time it runs through the loop $itime equals the name of the textfield. Because they can edit the entry after submitting it, there is a strlen thing and if it ==0(So if it hasnt ever been set) then it inserts it(or it should...) and if there is a previous entry then it will use an UPDATE statement. I know it goes through the loop right as it echoes the line below the INSERT statement, so im assuming there is an error with the syntax of my insert statement and/or update statement?

Thanks...
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: It wont insert into table? :S

Post by oscardog »

Bumpity Bump.

Oscardog
Post Reply