What I'm I doing wrong when trying to send data to an external database via jquery / ajax
I'm building a phonegap android app and trying to send data via the phone to an external database. I know the php side of things works as I wrote to the database and tested the variable etc but I think it's something wrong with the javascript side of thing but I have know idea what.
Please help
This is my index.html form that I want to send: (Clientside)
- <div id="sendInfomation" sendInfomation="1">
<form id="form">
<label for="phoneNumber">
<b>Phone Number</b>
<input type="number" id="phoneNumber" name="phoneNumber" />
</label>
<label for="firstName">
<b>First Name</b>
<input type="text" id="firstName" name="firstName" />
</label>
<label for="lastName">
<b>Last Name</b>
<input type="text" id="lastName" name="lastName" />
</label>
<label for="currentDate">
<b>Current Date</b>
<input type="date" id="currentDate" name="currentDate" value="" />
</label>
<label for="currentTime">
<b>Current Time</b>
<input type="time" id="currentTime" name="currentTime" />
</label>
<input type="submit" value="Save">
</form>
</div>
This is the post.js script I'm using to send the form: (Clientside)
- i$(document).bind('deviceready', function(){
$(function(){
$('form').submit(function(){
var sendData = $(this).parent().attr('sendInfomation');
var postData = $(this).serialize();
$.ajax({
type: 'POST',
data: postData + '&lid=' + sendData,
//change the url for your project
url: 'http://www.stuartwestgate.co.uk/final_project/save.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;
});
});
});
and this is the save.php script (Serverside):
- $phoneNumber = mysqli_real_escape_string($_POST["phoneNumber"]);
$firstName = mysqli_real_escape_string($_POST["firstName"]);
$lastName = mysqli_real_escape_string($_POST["lastName"]);
$currentDate = mysqli_real_escape_string($_POST["currentDate"]);
$currentTime = mysqli_real_escape_string($_POST["currentTime"]);
//$sql = "INSERT INTO member (phoneNumber, firstName, lastName, profilePicture, photo, video, textMessage, callData, activityData, latitudePos, longitudePos, currentDate, currentTime) VALUES ('$phoneNumber', '$firstName', '$lastName', '$profilePicture', '$photo', '$video', '$textMessage', '$callData', '$activityData', '$latitudePos', '$longitudePos', '$currentDate', '$currentTime')";
$sql = "INSERT INTO member (phoneNumber,firstName, lastName, currentDate, currentTime) VALUES ('$phoneNumber', '$firstName', '$lastName', '$currentDate', '$currentTime')";
if (!mysqli_query($connection, $sql)) {
die('Error: ' . mysqli_error($connection));
} else {
echo "Comment added";
}
mysqli_close($connection);
?>