2017-04-08 153 views
-2

我們都遇到了一個奇怪的錯誤,下面的代碼運行很順利,但是從15天開始它不工作,並且不會給我帶來錯誤。這個代碼有什麼問題,還有其他可用的選項。我有我希望填補所有記錄,然後轉移到數據庫的API。工作正常,但不工作,請檢查。在php中解析json

<?php 

      $servername = "localhost"; 
         $username = "root"; 
         $password = "com"; 
         $dbname = "sabk"; 
    $con = mysql_connect($servername,$username,$password) or die('Could not connect: ' . mysql_error()); 


    mysql_select_db($dbname, $con); 
    $jsondata = file_get_contents('http://tools.vcommission.com/api/coupons.php?apikey=e159f64e3dd49fddc3bb21dcda70f10c6670ea91aac30c7cb1d4ed37b20c45b8'); 
    echo "<script>console.log($jsondata);</script>"; 
    echo $jsondata; 
    $data = json_decode($jsondata, true); 


    foreach ($data as $row) 
    { 
     $promo_id=$row['promo_id']; 
     $offer_name=$row['offer_name']; 
     $coupon_title=$row['coupon_title']; 
     $category=$row['category']; 
     $coupon_description=$row['coupon_description']; 
     $coupon_type=$row['coupon_type']; 
     $coupon_code=$row['coupon_code']; 
     $link=$row['link']; 
     $coupon_expiry=$row['coupon_expiry']; 
     $added=$row['added']; 
     $store_image=$row['store_image']; 
     $sql = "INSERT INTO Vcom(promo_id,offer_name,coupon_title,category,coupon_description,coupon_type,coupon_code,link,coupon_expiry,added,store_image) 
    VALUES('$promo_id' ,'$offer_name','$coupon_title','$category','$coupon_description','$coupon_type','$coupon_code','$link','$coupon_expiry','$added','$store_image')"; 
    $retval = mysql_query($sql, $con); 

    if(!$retval) 
    { 
     $sql = "UPDATE Vcom SET offer_name=$offer_name,coupon_title=$coupon_title,category=$category, 
     coupon_description=$coupon_description ,coupon_type=$coupon_type,coupon_code=$coupon_code, 
     link=$link,coupon_expiry=$coupon_expiry,added=$added 
    WHERE promo_id=$promo_id"; 
    mysql_query($sql, $con); 
      echo "Data Updated ".'<br>'; 

    } 
    else 
    { 
     echo "Entered data successfully\n"; 
    } 






    } 
    mysql_close($con); 
?> 
+0

我們需要知道你得到的錯誤。 – Vallentin

+0

我沒有得到errror它的任何空白檢查輸出http://sabkideal.com/flipkart/vcom.php –

+0

你應該使用INSERT ... ON DUPLICATE KEY UPDATE而不是在INSERT ... ON INSERT ... ON UPDATE '失敗。您在'UPDATE'查詢中缺少大量引號。 – Barmar

回答

0

爲了在頁面中添加,顯示錯誤:

error_reporting(E_ALL);  
ini_set('display_errors', 'On');