私はphpが初めてです。webservice を使用して Android を phpmyadmin に接続しようとしています。
phpコード
<?php
include_once('configuration.php');
$UserId = $_POST['UserId'];
$ProductId = $_POST['ProductId'];
$DesiredQuantity = $_POST['DesiredQuantity'];
$cartstable=mysql_query("SELECT `UserId`, `ProductId`, `DesiredQuantity` FROM `carts` WHERE UId='".$UserId. "' AND ProductId='".$ProductId. "'");
$num_rows = mysql_num_rows($cartstable);
if($num_rows>0){
$updateqry=mysql_query("Update `carts` set `DesiredQuantity`= `DesiredQuantity` + $DesiredQuantity) WHERE UId='".$UserId. "' AND ProductId='".$ProductId. "');
}
else
{
$insertqry=mysql_query ("Insert into `carts` (`UId`, `ProductId`, `DesiredQuantity`) VALUES ('".$UserId. "','".$ProductId. "',$DesiredQuantity)");
}
$carts_ful=mysql_query("SELECT `UserId`, `ProductId`, `DesiredQuantity` FROM `CARTS` WHERE UId='".$UserId. "'");
while($carts = mysql_fetch_array($carts_ful)){
extract($carts);
$result[] = array("UserId" => $UserId,"ProductId" => $ProductId,"DesiredQuantity" => $DesiredQuantity);
}
$json = array("Updated Cart Details" => $result);
@mysql_close($conn);
header('Content-type: application/json');
// echo "Selected Product is added to the Cart !";
echo json_encode($json);
?>
実行しようとすると、次のエラーが表示されます
<b>Parse error</b>: syntax error, unexpected 'insert' .
切り貼りしたら、
$insertqry=mysql_query ("Insert into `carts` (`UId`, `ProductId`, `DesiredQuantity`) VALUES ('".$UserId. "','".$ProductId. "',$DesiredQuantity)");
if ステートメントの上の行、正常に動作します。
問題がどこにあるか理解できませんでした。解決策を見つけるのを手伝ってください。