2017-04-08 103 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');