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条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了