-3

我正在从我正在开发的患者系统中获取当前的葡萄糖读数。我使用 java 脚本获取当前日期/时间并通过表单隐藏字段过去。在下面的脚本中,我将日期部分存储在 3 个单独的变量中,然后将它们连接为 1,以便我可以在 mysql 的插入查询中使用它。我得到的错误是

解析错误:语法错误,意外的','希望有人能找到错误,因为我不明白通过在变量之间放置','我做错了什么。这是代码:

<?
SESSION_START();
include("DatabaseConnection.php");
//gather form data into variables
//gather parts of the date from hidden input fields
$Day = $_POST['Day'];
$Month = $_POST['Month'];
$Year = $_POST['Year'];

$Date = $Year, "-", $Month, "-", $Day; //line with error
//get hours and minutes from hidden fields
$Minutes = $_POST['Minutes'];
$Hours = $_POST['Hours'];
//concatinate date into 1 variable
$Time = $Hours, ":", $Minutes;

$GlucoseLevel = $_POST['GlucoseLevel'];
$SBP = $_POST['SBP'];
$DBP = $_POST['DBP'];
$Comments = $_POST['Comments'];
//store current user's id
$User_id = $_SESSION['User_id'];
//query for inserting reading
$ReadingInsert = "insert into reading
(Reading_id,
User_id,
Date,
Time,
GlucoseLevel,
SBP,
DBP,
Comments)
values(null,
'$User_id',
'$Date',
'$Time',
'$GlucoseLevel',
'$SBP',
'$DBP',
'$Comments')";

//run insert query
mysql_query($ReadingInsert) or die("Cannot insert reading");
`enter code here`mysql_close();
?>
4

5 回答 5

2

.在用于连接字符串的PHP中,请尝试:

$Date = $Year . "-" . $Month  "-" . $Day;

看:

http://php.net/manual/en/language.operators.string.php

于 2012-05-04T01:12:15.957 回答
1

php中的字符串连接.不使用, doc

于 2012-05-04T01:10:31.090 回答
0
$Date = $Year, "-", $Month, "-", $Day; //line with error

应该

$Date = $Year. "-". $Month. "-". $Day;  //<- Full "." and no ","
于 2012-05-04T01:10:08.400 回答
0

您还可以使用sprintf用变量插入字符串:

$Date = sprintf('%s-%s-%s', $Year, $Month, $Day); 
$Time = sprintf('%s:%s', $Hours, $Minutes);
于 2012-05-04T01:19:35.863 回答
0

我真正使用转义连接的唯一一次是使用函数,否则大括号{}是你的朋友!

$Date = "{$Year}-{$Month}-{$Day}";

您不必担心忘记经期或陷入尴尬"'"境地。爱花括号...爱他们!

于 2012-05-04T05:24:50.667 回答