Cannot insert in database and no error showing

			if(empty($errors)){  
				$sql ="INSERT INTO property (full_name,tax_dec,title_lot, property_type, location,block_lot_no, imageType, imageData, status, status1, tax_payer_id) 
				VALUES (?,?,?,?,?,?,?,?,?,?,?)";
				$query = $db->prepare($sql);		
				$query->bind_param("ssssssssssi",$_SESSION['fullname'],$_POST['tax_dec'],$_POST['title_lot'],$_POST['property_type'], $_POST['location'], $_POST['block_lot_no'], $imageProperties['mime'], $imgData, $status,$status1, $_SESSION['id'])or die(mysql_error());
				$query->execute(); 
				$message = "Record Added";
				header("refresh: 2; URL=property1.php");
			} 			

I cannot insert any data in my online website but on my local i can insert data

the message will show is Record Added but no data both in database and table

The execute call is probably failing due to a data type or duplicate error, but you have no error handling for all the database statements that can fail - connection, query, prepare, and execute.

In your two previous threads, similar to this one, a simple way of adding error handling for all those statements, by using exceptions for errors, was mentioned. Did you do that? Do you have any question about how to do that?

BTW the or die(mysql_error()) on the end of the bind_param line is meaningless. The mysql_error doesn’t work with the mysqli extension and even if you used mysqli_error, the bind_param call doesn’t do anything on the database server, so nothing exists for the mysqli_error to show. Simply remove the or die… in that line.

I really don’t know how to add those error handling. I only use this stuff if I met some problems in my codes.
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings …)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);

// Report all PHP errors
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set(‘error_reporting’, E_ALL);

Those are various php error_reporting settings. It should always be set to either E_ALL or even better -1. It should be set in the php.ini on your system. Those have nothing directly to do with setting the mysqli extension to use exceptions for errors. Indirectly, you must either display or log all php errors to see any uncaught exceptions, so that you will be able to see or log the actual mysqli error information. To enable exceptions for errors for the mysqli extension, add the following line of code before the point where you make the database connection -

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
1 Like

Ok thanks finally an error show I can now debug it.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.