0

Thanks in advance for your patience and help. New to writing code and have written the following code:

$host="localhost";
$username="#####";
$password="#######";
$db_name="signuplist";
$tbl_name="signupbydate";
$myusername=$_SESSION['logname'];

$cxn=mysqli_connect($host,$username,$password,$db_name)
     or die ("Couldn't Connect to Server");

$chkbox = array('playdate1', 'playdate2', 'playdate3', 'playdate4', 'playdate5');

if(isset($_POST['submit']))
{   $playdate = $_POST['playdate'];
    $values = array();
    foreach($chkbox as $selection )
    {     if(in_array($selection, $playdate))
            { $values[ $selection ] = 1;  }
          else
            { $values[ $selection ] = 0;  }
    } // end of foreach.

    // MySQL statement. Don't forget to strip to avoid sql injection 

  $sql1="UPDATE ".$tbl_name." 
         SET playdate1='".$_POST["playdate1".$playdate]."', playdate2='".$_POST["playdate2".$playdate]."', playdate3='".$_POST["playdate3".$playdate]."', playdate4='".$_POST["playdate4".$playdate]."', playdate5='".$_POST["playdate5".$playdate]."' 
         WHERE username=$myusername;

         // MySQL statement to execute the UPDATE statement above.           
          mysqli_query($cxn, $sql1) or die('<br/>Error reading database: '.mysqli_error($cxn));
          mysqli_close($cxn);
}  // End of, if statement from the button check
?>

<html>
    <head>
        <title>Checkbox</title>
    <head>
         <title>HTML Checkbox</title>
    </head>
    <body>
    <div style='margin-left:6.0in; margin-top:0.75in'>
    <p style='font-weight:bold'>
        When would you like to play golf?</p>
    <p>Choose the dates you wish to play</p>
    <p>Make sure you click 'Update' when you are done</p>
           <form name="requesttime" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
           <input type="checkbox" name="playdate[]" value="playdate1"> September 3, 2014 <br>
           <input type="checkbox" name="playdate[]" value="playdate2"> September 6, 2014 <br>
           <input type="checkbox" name="playdate[]" value="playdate3"> September 10, 2014 <br>
           <input type="checkbox" name="playdate[]" value="playdate4"> September 13, 2014 <br>
           <input type="checkbox" name="playdate[]" value="playdate5"> September 17, 2014 <br>
           <br>
           <input type="submit" value="Update" name="submit">
         </form>
    </body>
</html>

I originally used INSERT instead of UPDATE and did not get any error messages, but now with the UPDATE line I get this error message which I have tried for about a day to resolve:

Parse error: syntax error, unexpected 'requesttime' (T_STRING) in C:\xampp\htdocs\requesttime.php on line 55

The 'username' field in the database is VARCHAR (25) and the 'playdate' fields are ENUM (1) with values of either '0' or '1' and a default value of '0' if that has any bearing

I understand there are likely more efficient ways to do this and also to process the input but I am enjoying the learning process so will get there next Thanks!

user3830570
  • 21
  • 1
  • 6

1 Answers1

0

Change

WHERE username=$myusername;

To

WHERE username=$myusername";
Alex
  • 1,565
  • 2
  • 9
  • 13