在MySQL数据库中插入PhoneGap数据

时间:2013-06-06 01:30:36

标签: php html mysql jquery cordova

我是PhoneGap的新手,我找到了使用jQuery在mysql数据库中插入数据的教程。但问题是我无法执行此示例。没有在mySql中插入数据的结果。任何人都可以告诉我什么是我的错误或是否有最简单的方法从phoneGap插入mysql数据?谢谢。

当我在模拟器中尝试这个时,这是我的Logcat

06-06 16:25:25.425: E/Trace(769): error opening trace file: No such file or directory (2)
06-06 16:25:25.646: I/CordovaLog(769): Changing log level to DEBUG(3)
06-06 16:25:25.655: I/CordovaLog(769): Found preference for useBrowserHistory=true
06-06 16:25:25.655: D/CordovaLog(769): Found preference for useBrowserHistory=true
06-06 16:25:25.675: I/CordovaLog(769): Found preference for exit-on-suspend=false
06-06 16:25:25.675: D/CordovaLog(769): Found preference for exit-on-suspend=false
06-06 16:25:25.675: D/DroidGap(769): DroidGap.onCreate()
06-06 16:25:25.855: D/dalvikvm(769): GC_FOR_ALLOC freed 70K, 8% free 
2480K/2672K,paused  82ms, total 86ms
06-06 16:25:25.875: I/dalvikvm-heap(769): Grow heap (frag case) to 3.144MB for   
635812-byte allocation   
06-06 16:25:25.945: D/dalvikvm(769): GC_FOR_ALLOC freed 1K, 6% free 3099K/3296K, 
paused 69ms, total 69ms
06-06 16:25:26.045: D/dalvikvm(769): GC_CONCURRENT freed <1K, 6% free 3110K/3296K, 
paused 7ms+29ms, total 81ms
06-06 16:25:26.255: D/CordovaWebView(769): CordovaWebView is running on device made 
by: unknown
06-06 16:25:26.275: D/JsMessageQueue(769): Set native->JS mode to 2
06-06 16:25:26.315: D/DroidGap(769): DroidGap.init()
06-06 16:25:26.405: D/CordovaWebView(769): >>> loadUrl(file:///android_asset
/www/track.html)
06-06 16:25:26.405: D/PluginManager(769): init()
06-06 16:25:26.445: D/CordovaWebView(769): >>> loadUrlNow()
06-06 16:25:26.464: D/DroidGap(769): Resuming the App
06-06 16:25:26.615: D/SoftKeyboardDetect(769): Ignore this event
06-06 16:25:26.705: D/gralloc_goldfish(769): Emulator without GPU emulation detected.
06-06 16:25:27.025: D/SoftKeyboardDetect(769): Ignore this event
06-06 16:25:27.465: D/DroidGap(769): onMessage(onPageStarted,file:///android_asset
/www/track.html)
06-06 16:25:28.964: D/chromium(769): Unknown chromium error: -6
06-06 16:25:29.064: D/chromium(769): Unknown chromium error: -6
06-06 16:25:29.394: D/CordovaNetworkManager(769): Connection Type: 3g
06-06 16:25:29.394: D/DroidGap(769): onMessage(networkconnection,3g)
06-06 16:25:29.394: D/CordovaNetworkManager(769): Connection Type: 3g
06-06 16:25:29.414: D/DroidGap(769): onMessage(spinner,stop)
06-06 16:25:29.554: D/TilesManager(769): Starting TG #0, 0x2a2276a8
06-06 16:25:29.594: D/Cordova(769): onPageFinished(file:///android_asset
/www/track.html)
06-06 16:25:29.594: D/DroidGap(769): onMessage(onPageFinished,file:///android_asset
/www/track.html)
06-06 01:14:49.216: D/SoftKeyboardDetect(769): Ignore this event
06-06 01:14:52.746: D/SoftKeyboardDetect(769): Ignore this event
06-06 01:14:55.016: D/DroidGap(769): onMessage(onPageStarted,file:///android_asset  
/www/track.html?email=wwwww&comment=ww)
06-06 01:14:55.196: D/chromium(769): Unknown chromium error: -6
06-06 01:14:55.476: D/CordovaNetworkManager(769): Connection Type: 3g
06-06 01:14:55.486: D/DroidGap(769): onMessage(spinner,stop)
06-06 01:14:55.486: D/chromium(769): Unknown chromium error: -6
06-06 01:14:55.518: D/Cordova(769): onPageFinished(file:///android_asset
/www/track.html?email=wwwww&comment=ww)
06-06 01:14:55.518: D/DroidGap(769): onMessage(onPageFinished,file:///android_asset  
/www/track.html?email=wwwww&comment=ww)

这是我的track.html

<!DOCTYPE html>
<html>
 <head>
<title>Device Properties Example</title>

<script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
<script type="text/javascript" charset="utf-8" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
$('form').submit(function(){
    var landmarkID = $(this).parent().attr('data-landmark-id');
    var postData = $(this).serialize();

    $.ajax({
        type: 'POST',
        data: postData+'&amp;lid='+landmarkID,
        url: 'http://192.168.254.105/webs/main/track.php',
        success: function(data){
            console.log(data);
            alert('Your comment was successfully added');
        },
        error: function(){
            console.log(data);
            alert('There was an error adding your comment');
        }
    });

    return false;
});

 </script>
 </head>
   <div id="landmark-1" data-landmark-id="1">
<form>
    <label for="email">
        <b>Email</b>

            <input type="email" id="email" name="email">
    </label>

    <label for="comment">
        <b>Comment</b>
        <textarea id="comment" name="comment" cols="30" rows="10"></textarea>
    </label>

    <input type="submit" value="Save">
</form>
   </div>
  <body>


       </body>
    </html>

这是我的track.php

  <?php
  $server = "localhost";
  $username = "root";
  $password = "";
  $database = "comments";

  $con = mysql_connect($server, $username, $password) or die ("Could not connect: " .  
  mysql_error());
  mysql_select_db($database, $con);

  $locationID = $_POST["lid"];
  $email = mysql_real_escape_string($_POST["email"]);
  $comment = mysql_real_escape_string($_POST["comment"]);

  $sql = "INSERT INTO comment (location_id, email, comment) ";
  $sql .= "VALUES ($locationID, '$email', '$comment')";

   if (!mysql_query($sql, $con)) {
die('Error: ' . mysql_error());
   } else {
echo "Comment added";
    }

   mysql_close($con);
    ?>

感谢您的帮助!

0 个答案:

没有答案