Reputation: 1313
I know this has been asked many times before but I can't figure out why this query won't insert records into a mysql database. I get a success message but the records are not actually placed into the table. I've spent hours on it and just can't figure it out so any help would be much appreciated. I've just updated my server to php 5.6 from 5.3.
<?php
session_start();
$mysqli = new mysqli("localhost", "root", "usernmae", "mydatabase");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
include "php_includes/display_errors.php"; //show errors
if(isset($_SESSION['user_session']) && !empty($_SESSION['user_session'])) {
//Update Database
$stmt = $mysqli->prepare("INSERT INTO tbl_collab (collab_userid, collab_username, file, tbl_upload_id) VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss',$user_id, $user_name, $file, $page_id);
$user_id = $_POST['user_id'];
$user_name = $_POST['user_name'];
$file= $_POST['file'];
$page_id= $_POST['page_id'];
$stmt->execute();
if($stmt){
echo"success";
}
else {
echo "error";
}
}
// Close connection
mysqli_close($mysqli);
?>
Upvotes: 0
Views: 40
Reputation: 362
Cross check the data types. If the data type are same then print the error message using $stmt->error and report the error.
Upvotes: 1