-4

I am getting a strange error in my php code, and I can't figure out why!
The error: Parse error: syntax error, unexpected '=' on line 9

<?php
session_start();

$name = $_POST['Contact-Name'];
$address = $_POST['Contact-address'];
$email = $_POST['Contact-Email'];
$phone = $_POST['Contact-Phone'];
$program = $_POST['Program-Name'];
$date-requested = $_POST['date-requested'];

$timestart = $_POST['program-start-time'];
$timeend = $_POST['program-end-time'];

$timestart-format = $_POST['starttime-format'];
$timeend-format = $_POST['endtime-format'];

$full-start-time = $timestart." ".$timestart-format;
$full-end-time = $timeend." ".$timeend-format;


//the book king hours
$mon-thurs-hours = array("10:00 AM", "11:00 AM", "12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM", "5:00 PM", "6:00 PM");
$friday-hours = array("10:00 AM", "11:00 AM", "12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM", "5:00 PM", "6:00 PM", "7:00 PM", "8:00 PM");
$saturday-hours = array("10:00 AM", "11:00 AM", "12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM", "5:00 PM", "6:00 PM");

//find the day of the week and save to $dayofweek
$date = new DateTime();
$timestamp = date_timestamp_get($date-requested);
$dayofweek = date( "w", $timestamp);

//if sunday
if($dayofweek == 0){
echo "You choose Sunday!";
die('Sorry, the book king is closed on Sundays!');
}

//if monday, tues, wed, thurs
if(($dayofweek == 1)||($dayofweek == 2)||($dayofweek == 3)||($dayofweek == 4)){
echo "You choose day ".$dayofweek."!";
//see if bk is open at the specified times
if (in_array($full-start-time, $mon-thurs-hours)) {
  echo "Start time is okay!";
    }
    if (in_array($full-end-time, $mon-thurs-hours)) {
      echo "End time is okay!";
    }
}

//if friday
if($dayofweek == 5){
    echo "You choose day ".$dayofweek."!";
//see if bk is open at the specified times
if (in_array($full-start-time, $friday-hours)) {
  echo "Start time is okay!";
}
    if (in_array($full-end-time, $friday-hours)) {
      echo "End time is okay!";
    }
}

//if saturday
if($dayofweek == 6){
echo "You choose day ".$dayofweek."!";
    //see if bk is open at the specified times
    if (in_array($full-start-time, $saturday-hours)) {
      echo "Start time is okay!";
    }
    if (in_array($full-end-time, $saturday-hours)) {
      echo "End time is okay!";
    }
}

?>

I'm not sure if you need all that code, or just the first 9 lines, but I posted it all just in case!

I really appreciate your help with this!

pattyd
  • 5,927
  • 11
  • 38
  • 57
  • How is the variable on that line different from the preceding ones? What do you use the different symbol for in PHP? – Wooble Aug 31 '13 at 19:29
  • possible duplicate of [Mail Script - Parse error: syntax error, unexpected '='](http://stackoverflow.com/questions/18294546/mail-script-parse-error-syntax-error-unexpected) – mario Aug 31 '13 at 20:43
  • possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/q/18050071) – mario Aug 31 '13 at 20:44

2 Answers2

3

The problem is in $date-requested identifier. You can not use - in identifier. Identifier may contain only letters, digits, and underscope (_) and must start with letter or underscope.

So it is interpreted as expression (variable $date minus constant requested), and the whole line as an assigment to that expression, which make no sense to PHP processor. That's why you get such strange error message.

Use valid variable name like $date_requested

mas.morozov
  • 2,666
  • 1
  • 22
  • 22
  • Thanks! Never even noticed that a `-` was disallowed. How about in the `$_POST` variables? Will it cause an issue there? – pattyd Aug 31 '13 at 19:34
  • `-` is a mathematical operator. obviously you cannot use it in variable names.... but it's fine for form elements. – Karoly Horvath Aug 31 '13 at 19:38
  • `$_POST` array, just like all other PHP arrays, allow any string to be a key. So `$_POST['date-requested']` is valid, but I would not recommend to intentionally use such string keys, not beeing valid identifiers, just because later you may want to use `extract` on the array or convert it to object. – mas.morozov Aug 31 '13 at 19:44
  • Thanks guys, I appreciate your help and support! :) – pattyd Aug 31 '13 at 19:46
1

$date-requested is not a valid variable name (cannot include a hyphen), use $date_requested or similar instead.

Brad Peabody
  • 10,917
  • 9
  • 44
  • 63