-4

我的 php 代码出现一个奇怪的错误,我不知道为什么!
错误: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!";
    }
}

?>

我不确定您是否需要所有这些代码,或者只需要前 9 行,但我将其全部发布以防万一!

我真的很感谢你的帮助!

4

2 回答 2

3

问题出在$date-requested标识符中。您不能-在标识符中使用。标识符只能包含字母、数字和下划线 ( _),并且必须以字母或下划线开头。

所以它被解释为表达式(变量$date减去常量requested),整行作为该表达式的赋值,这对 PHP 处理器没有意义。这就是为什么您会收到如此奇怪的错误消息。

使用有效的变量名,例如$date_requested

于 2013-08-31T19:31:37.653 回答
1

$date-requested不是有效的变量名称(不能包含连字符),请改用$date_requested或类似名称。

于 2013-08-31T19:28:41.707 回答