duan97689 2013-09-01 01:11
浏览 99
已采纳

在mysql中插入数据先前定义的变量

I am using this code to get data from Json and insert them to mysql. However it inserts no records in the data base.

    <?php  
    include("db.php");  
    $currsiteurl = 'http://graph.facebook.com/1597233119';  
     $graph = json_decode(file_get_contents($currsiteurl));  
     $id = $graph->id;  
     echo "id        : ".$id;   
     echo "<br>";
     $username = $graph->username;  
      echo "username : ".$username;  
      echo "<br>";
     $gender = $graph->gender;  
      echo "gender   : ".$gender;  
      echo "<br>";
       $locale = $graph->locale;  
         echo "locale   : ".$locale;  


        mysql_query("INSERT INTO users_data (id, username, gender, locale) 
         VALUES ('.$id', '.$username', '.$gender', '.$locale')");    
          ?>

Can any one show me whereis the mistake ?

  • 写回答

2条回答 默认 最新

  • ds42774 2013-09-01 01:15
    关注
    mysql_query("INSERT INTO users_data (id, username, gender, locale) 
         VALUES ('.$id', '.$username', '.$gender', '.$locale')");  
    

    You are creating a single string (with embedded variables) so the dots '.' are not required.

    If either of the id or gender are number-fields then this is likely to be what prevents the data from being inserted (with the dots). (If they are numbers they don't require surrounding apostrophes either.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件