jquery - AJAX POST to PHP script -
i'm trying post program separate php file, grab data , store sql database. i've checked code on , on , can't' find i'm doing wrong. appreciated.
ajax
$(".btn btn-success last").click(function(){ $.post("go2.php", { name: "donald duck", city: "duckburg" }, function(data, status){ alert("data: " + data + "\nstatus: " + status); }); });
php file (go2.php) w/ sql code
<?php include 'connection.php'; $x = $_post["name"]; $sql = "insert users (username) values ('$x') "; $query = mysql_query($sql); ?>
try long version of ajax request
$(document).ready( function () { $(".btn btn-success last").click(function(){ $.ajax({ type: "post", url: "go2.php", data: {name:"donald duck", city:"duckburg"}, success: function(data){ document.getelementbyid('divid').html(data); } }); }); });
for echo data, have echo message in go2.php "success"
Comments
Post a Comment