dpp66953 2013-08-31 19:26
浏览 14
已采纳

php中的意外'='[关闭]

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!

  • 写回答

2条回答 默认 最新

  • doubaomao9304 2013-08-31 19:31
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路