php - Problem in Ajax connection -


this small code getting twitter profile , saving in database.

i using xampp 1.7.3 , saving php file in c://xampp/htdocs/tweet/index.php.

database name: test

table name: demotable

i new in ajax , php.

problem: database table not showing data!

index.php

    <head>         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>         <script type="text/javascript">             $(function()             {                 $('#btn').click(function()                 {                     twitterusername = $('#uname').val();                     if (twitterusername != '')                     {                         $('#loading').text('please wait...');                         $.getjson('http://twitter.com/users/'+twitterusername+'.json?callback=?',                         function(data)                         {                             $('#loading').empty();                             $('#twit_uname').html('<b>'+data.screen_name+'</b>');                             $('#twit_frnd').html('<b>'+data.friends_count+'</b>');                             $('#twit_name').html('<b>'+data.name+'</b>');                             $('#twit_flwr').html('<b>'+data.followers_count+'</b>');                             $('#twit_img').html('<img src="'+data.profile_image_url+'" height="50" width="50">');                             $.ajax({                                 type: "post",                                 url: "test.php",                                 data: "tname="+data.name+"&tusername="+data.screen_name+"&tfollowers="+data.followers_count+"&tfollowing="+data.friends_count,                                 success: function(msg) {                                     alert( "data saved: " + msg );                                 }                             });                         });                     }                 });             })         </script>         <style>             div{float:right; border-bottom:1px dashed #909; margin-bottom:2px;}             li{border-bottom:1px dashed #909; margin-bottom:10px;}             .main{             margin:auto;    border:1px solid #cc0;    float:none;    width:1000px;    padding:10px;    font-family:verdana, geneva, sans-serif;    font-size:16px;    color:#000000;}             b{float:left; text-align:left;}         </style>     </head>     <body>         <div class="main">             enter twitter username : <input type="text" name="user" id="uname">             <input type="button" value="get profile" id="btn"><br />             <div id="loading" align="center"></div>             <ul>                 <li>name : <div id="twit_name"></div></li>                 <li>username : <div id="twit_uname"></div></li>                 <li>followers : <div id="twit_flwr"></div></li>                 <li>following : <div id="twit_frnd"></div></li>                 <li>profile image : <div id="twit_img" style="border:1px solid #999999; height:50; width:50;"></div></li>             </ul>         </div>     </body> </html> 

test.php

<?php     $link = mysql_connect('localhost', 'root', 'password');     if (!$link) {         die('not connected : ' . mysql_error());     }     $db_selected = mysql_select_db('test', $link);     if (!$db_selected) {         die ('can\'t use foo : ' . mysql_error());     }     $t_name=$_request['tname'];     $t_username=$_request['tusername'];     $t_followers=$_request['tfollowers'];     $t_following=$_request['tfollowing'];     if (mysql_query("insert demotable (name, username, followers, following) values ('" .                      $t_name . "', '" .                      $t_username . "', '" .                      $t_followers. "', '" .                      $t_following . "') "                     ))     {         echo "data saved successfully";     }     else     {         echo "error in saving data";     }     exit     mysql_close($link); ?> 


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -