php代码既不会产生结果也不会产生错误

时间:2014-07-02 12:30:29

标签: php mysql json web-services

我有一个服务器脚本,我允许用户将任何项目标记为收藏,但我还想要另一个脚本,用户可以通过该脚本不需要相同的项目,如果他们想要该项目应该从他们喜欢的列表中删除。我为喜欢和不喜欢的代码保留了相同的表格。为此,我有一个代码

<?php
    require_once('config.php');
    $favorite = $_REQUEST['favorite'];
    $unfavorite = $_REQUEST['unfavorite']; 
    $id=$_REQUEST['id'];

$unfavoritedeal=mysql_query("SELECT * FROM favoritedeals where id='".$id."'"); //favoritedeals is the name of the table

if($row=mysql_fetch_array($unfavoritedeal))
       {
          $favorite=$row['favorite'];
          $unfavorite=$row['unfavorite'];
       }

          $myfavorite=(isset($_REQUEST['favorite'])?$_REQUEST['favorite']:$favorite);
          $myunfavorite=(isset($_REQUEST['unfavorite'])?$_REQUEST['unfavorite']:$unfavorite);

$update = mysql_query("update favoritedeals set favorite = '".$myfavorite."', unfavorite = '".$myunfavorite."' where id = '".$id."'");  


    $posts[0]['message'] = 'favorite list updated';
    $selectt = mysql_query("select * from favoritedeals where id = '".$id."'");
    $results =  mysql_fetch_assoc($selectt);
    $posts[0]['detail'] = $results;

if($unfavorite="0" where id='".$id."')
  {
 $sql="delete from favoritedeals WHERE id='".$id."'";     
  if(mysql_query($sql)) 
     {
        header('Content-type: application/json');
        echo json_encode(array('favorite deals'=>'Deal has been updated'));   
     }
  else
     {
        header('Content-type: application/json');
        echo json_encode(array('favorite deals'=>'Deal not updated'));
     }  

}

$selectt = mysql_query("select * from favoritedeals where id = '".$id."'");
$results =  mysql_fetch_assoc($selectt);
$posts[0]['detail'] = $results;
header('Content-type: application/json');
echo json_encode($posts);

&GT;

当我运行此代码时,它既不会显示错误也不会产生所需的结果。任何人都可以建议我一个正确的代码/解决方案

1 个答案:

答案 0 :(得分:1)

尝试使用此代码顶部的文件。

error_reporting(-1);

更多详情:http://www.php.net/manual/en/function.error-reporting.php