-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 での文字列連結は.not , docを使用します

于 2012-05-04T01:10:31.090 に答える
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; //line with error

する必要があります

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

私がエスケープ連結を実際に使用するのは、関数を使用するときだけ{}です。

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

生理を忘れたり、気まずい"'"状況に遭遇したりすることを心配する必要はありません。中かっこが大好き...大好き!

于 2012-05-04T05:24:50.667 に答える