php - Post variable via ajax to mysql db - phonegap -
i want post simple variable phonegap app mysql database. dont work. db show me empty results.
mysql database looks this, tablename user
rows:
user (varchar 25),vip (varchar 1),call (varchar 1)
at top of project inserted:
<script type="text/javascript" src="js/tcplugin.js"></script> <script type="text/javascript" src="js/phoneapp.js"></script> <script type="text/javascript" src="js/start.js"></script>
start.js file ajax request - other 2 working fine guess there not problem
my start.js file looks this:
$(document).ready( function() { var email = "john@web.de"; $.ajax({ type: 'post', url: 'http://www.blablabla.de/phone/action.php', data: { data: {"email" : email }, //data:email, }, success: function(result) { console.log(result); } });
and action.php looks this:
<?php $dbhost = "bla"; $dbuser = "bla"; $dbpass = "bla"; $dbname = "bla"; $user = $_post['data']['email']; $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "insert user (email) values ('" . $user . "')"; if ($conn->query($sql) === true) { echo "new record created successfully"; } else { echo "error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>
but everytime start app db empty. debugger concole not giving me errors. db connection working, tried echo connection result. , other js working fine.
action.php
<?php $dbhost = "bla"; $dbuser = "bla"; $dbpass = "bla"; $dbname = "bla"; print_r($_post); // see full contents of post $user = $_post['data']['email']; print php_eol . $user . php_eol; // see full contents of $user var $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "insert user (email) values ('" . $user . "')"; print php_eol . $sql . php_eol; // see actual sql query, can test later in sql editor ex. phpmyadmin if ($conn->query($sql) === true) { echo "new record created successfully"; } else { echo "error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>
make these edits, run ajax , check response tab in debugger.
Comments
Post a Comment