Code for Book record management

I don’t understand can you please explain to me what is this statement"oddly, the database reports that the default for title and price are NULL, which would violate their NOT NULL designators. Presumably the database is coercing NULL to “” and 0.00 respectively" means?

You would use var_dump() anywhere you need to know the contents of a variable. So in your form-processing code, you could put it just before you start assigning the form values to local variables.

$Title=mysqli_real_escape_string($con, $_REQUEST ['title']);
$Price=mysqli_real_escape_string($con, $_REQUEST ['price']);
$Author=mysqli_real_escape_string($con, $_REQUEST ['author']);

As @brianjamestorr said earlier, though, check your database column names for case sensitivity. In your image of the database layout, you have these three column names:


In your query, you try to update


which as you can see, is different. I haven’t come across this problem before, but I tend to do all my stuff in lower-case anyway. The doc suggests that not all MySQL servers care about case, but it’s worth a try.

This means that in your database, you have default values set for the title and price columns of NULL, but you also don’t allow NULL to be stored in those columns. So if you don’t provide a value in either of those columns, it will default to NULL, which is not allowed, and the insert will fail. So you either have to make sure you are not inserting NULL values there (by perhaps checking and throwing an error back to you user), or allow NULL, or set a default value.

C:\wamp64\www\BRM\insertion.php:12: array (size=3) ‘title’ => string 'Harry Poter ’ (length=12) ‘price’ => string ‘444.5’ (length=5) ‘Author’ => string ‘JK Rowling’ (length=10)

insertion failed

Book Record Management

click here

This is result

OK, there’s a difference. In your code:

$Title=mysqli_real_escape_string($con, $_REQUEST ['title']);
$Price=mysqli_real_escape_string($con, $_REQUEST ['price']);
$Author=mysqli_real_escape_string($con, $_REQUEST ['author']);

all of your form field names are lower case. In your var_dump() though, you can see that they are not:

array (size=3) 
  ‘title’ => string 'Harry Poter ’ (length=12) 
  ‘price’ => string ‘444.5’ (length=5) 
  ‘Author’ => string ‘JK Rowling’ (length=10)

I’m not sure why that makes it fail, because the author is the column where a null is allowed. Have you tried making sure, as above, that the column names are the correct case?

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