Column ‘images’ cannot be null
How to fix it.
Column ‘images’ cannot be null
How to fix it.
Make sure you don’t have any nulls in your images column.
No i dont have it.
As you should know by now, you need to provide more information if you want help. The more detailed your post, the easier it is for others to assist. Include all relevant code.
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO blog1 (`name`, `comment`, `email`, `images`) VALUES (%s, %s, %s, NULL)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['images'], "text"));
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
--
-- Table structure for table `blog1`
--
CREATE TABLE `blog1` (
`id` int(11) NOT NULL,
`name` text NOT NULL,
`comment` text NOT NULL,
`email` text NOT NULL,
`images` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Notice the table schema has all fields as NOT NULL
Notice the INSERT is trying to insert a NULL
INSERT INTO blog1 (`name`, `comment`, `email`, `images`)
VALUES (%s, %s, %s, NULL)
You have a few things you can do
still not working
How about telling us what you changed.
That seems unusual. It’s worked for me.
hmmm’
added this
if(!empty($_POST['images'])){
$images= $_POST['images'];
and got blank page
Your biggest problem is that you are using dangerous, obsolete code that has been completely removed from PHP. You need to use PDO with Prepared Statements.
Here is a tutorial to get you going https://phpdelusions.net/pdo
type or paste code here$servername = "localhost";
$username = "root";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("INSERT INTO blog1 (name, comment, email,images) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $name, $comment, $email,$images);
// set parameters and execute
$name = "name";
$comment = "comment";
$email = "email";
$images = "images";
$stmt->execute();
echo "New records created successfully";
$stmt->close();
$conn->close();
I got like that but cant get data in db no errors.
You have a syntax error.
The “type or paste code here” comment needs to be a comment. Either with two forward slashes like the others
// Create connection
// Check connection
// set parameters and execute
or like
# type or paste code here
or
/* type or paste code here */
type or paste code here comment is row in db.where is error
Well, whatever line the comment is on, it needs to be a comment (or removed). Otherwise the script will break there and nothing after it will run.
I suspect that bit is from this forum - when you click the button on top of the reply box to switch to formatted text, it inserts the string “type or paste code here”, and I think @capljina2 has just not removed it from the post. So it’s not in the actual code they are trying to run.
In this query:
"INSERT INTO blog1 (name, comment, email,images) VALUES (?, ?, ?, ?)"
you don’t specify the id
column at all. But in your table layout in post #5 above, it’s marked as “not null”, but has no default value. So you either need to give it a default value (which I’d presume would be to make it auto-increment) or specify the value in the query.
still has an error