This is my server side code:
$pic=$_FILES['file-0']['tmp'];
$type = $_POST['type'];
$address = $_POST['address'];
$nums = $_POST['nums'];
$lng = $_POST['lng'];
$lat = $_POST['lat'];
$signal = $_POST['sigs'];
$time = $_POST['time'];
$date = $_POST['date'];
$image_name=uploadImage($_FILES);
$db = new mysqli( '', '', '', '' );//deleted the connection string parameters
if ( $db->connect_errno > 0 ) {
die( 'Unable to connect to database [' . $db->connect_error . ']' );
} else {
echo 'connected to db';
}
if(!($stmt=$db->prepare("INSERT INTO mytable(number, address, signals, time, date, lat, lng, type,image) VALUES (?,?,?,?,?,?,?,?,?)"))){
echo "Prepare failed: (" . $db->errno . ") " . $db->error;
}
if(!($stmt->bind_param("isissiiss",$nums, $address, $signal, $time, $date, $lat, $lng, $type,'user-img/'.$image_name))){
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if(!($stmt->execute())){
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
I'm using jquery ajax and try to get the error like this but it alerts just the whole html file markup without any errors:
$.ajax({
type:'POST',
url:'../index.php',
contentType:false,
processData : false,
data:data,
success: function(data) {
$('#load-page').fadeOut();
},
error:function(xhr, status, error) {
alert(xhr.responseText);
}
})
I'm sure that this works too because when I use this code without prepare and just write to the database with mysqli->query()
then everything works fine.
I have no access to the servers log files and can't read it so I tried to alert out the error like in the code above but it doesn't work.
for the $stmt->bind_param()
type parameters I tried to put everything as string (s)
but didn't work too.
I don't know what is wrong with my code. Any ideas?