I have problem in coding

<?php
	$Title=$_POST['title'];
	$Price=$_POST['price'];
	$Author=$_POST['author'];
	$con=mysqli_connect('localhost','root');
	mysqli_select_db($con,'BRM_DB');
	$query="INSERT INTO book (title,Price,Author) VALUES ('$Title',$Price,'$Author')";
	$result=mysqli_query($con,$query);
	mysqli_close($con);
	?>
	<!DOCTYPE html>
	<html>
	<head>
	<title>Insertion</title>
	</head>
	<body>
	<h1>Book Record Management</h1>
	<p>
	<?php 
	if($result==1)
	{
	echo ("Record inserted");
	}else { 
	echo ("insertion failed");
	}

	?>
	</p>
	<a href="insertform.php">click here</a>
	</body>
	</html>

it is coding and it gives me as result “insertion failed” why?

Because $result != 1. Easy, isn’t it? But that doesn’t really help, so you have a look into $result what it actually is: var_dump($result). I bet it’s false. So you got an error in the SQL query, but you have to explicit ask for it, so you set the config:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

at the beginning of your script.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service