2015-05-24 5 views
-1

Я новичок в php. Я пытаюсь подключить android с phpmyadmin, используя webservice.Ошибка анализа: синтаксическая ошибка, неожиданная «вставка»

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)"); 

линия выше, если заявление , Он отлично работает.

Я не мог понять, где проблема. Пожалуйста, помогите мне найти решение.

+0

Вы не закрываете строку в конце строки '$ updateqry = mysql_query'. –

+0

Используйте правильный редактор/IDE. Выделение синтаксиса указывало бы на ошибку, как это делает SO. (Ненавижу думать, * которые * Редактор люди, которые задают эти вопросы, используют ..) – user2864740

+0

Большое спасибо :-) Теперь отлично работает @ Jon Stirling –

ответ

1

Выделение синтаксиса стека переполнения должно быть достаточно, чтобы обнаружить ошибку.

Вы пропустили заключительную цитату из одного из ваших SQL-запросов. Найдите поправку ниже.

$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)"); 

} 
Смежные вопросы