Wondering if someone could help me. I have next to no knowledge with Ajax, and after many attempts at trying to pass my User1_id and Text through to my insert.php I've had no luck with inserting the data I want to my database.
As my profile.php and insert.php stands, the form submits to the database, but when the user submits the form it navigates to the insert.php and would rather have the Ajax send the data and stay on the Profile.php at all times, I feel this is a much better approach when creating such functions.
I'm wondering if someone can guide me in the right direction on how I'd go about doing this.
Profile.php Form
<form id="FormId" action="" method="get">
<input type="hidden" value="<? echo $user1_id ?>">
<textarea placeholder="Whats New??" id="FormId" name="status"></textarea>
<input type="submit" name="Submit" value="Submit">
</form>
Insert.php
<?
session_start();
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include "db_connect.php";
if (isset($_GET['status'])) {
$status = $_GET['status'];
}
$user1_id=$_SESSION['id'];
if ($_GET['status']) {
$query = mysql_query("INSERT INTO feed (status,user1_id) VALUES ('$status', '$user1_id')") or die (mysql_error());
if($query){
echo "Posted Into Database";
}
exit();
}
?>
I know I need something similiar to this.. But I think I'm stuck more on the var/data part.
$("form#myFormId").submit(function() {
var mydata = $("form#myFormId").serialize();
alert(mydata); // it's only for test
$.ajax({
type: "GET",
url: "insert.php",
data: mydata,
success: function(response, textStatus, xhr) {
alert("success");
},
error: function(xhr, textStatus, errorThrown) {
alert("error");
}
});
return false;
});
But don't know how to go about it.
Any guidence is appreciated. Not asking anyone to write the code out for me. But good direction is welcomed.
Thanks.