MySQL Forums
Forum List  »  PHP

submitting null value from php to MySql
Posted by: Nick Abelson
Date: October 29, 2020 01:46AM

Hi
I am stumped! My hosting company has a strict policy regarding the DB set up and won't change it as I am on a shared service.

I am retrieving values from a form in php and need to be able to write a null value to some fields, some of the time.

The table is set up to enter null by default for a given row.

CREATE TABLE `content_habitparameters` (
`Content_Habit_ID` int(100) NOT NULL,
`Habit_ID` int(100) NOT NULL,
`Content_ID` int(100) NOT NULL,
`Min_Value` int(10) DEFAULT NULL,
`Max_Value` int(100) DEFAULT NULL,
`yesorno` tinyint(1) DEFAULT NULL,
`Section_Generic` tinyint(4) DEFAULT NULL

PHP Code:

...
...
$minvalue = $_POST['minvalue'];
$maxvalue = $_POST['maxvalue'];
...
...

$insertcontenthabits = "INSERT INTO content_habitparameters (Content_ID, Habit_ID, Min_Value, Max_Value, yesorno, Section_Generic)
VALUES ('" . $contentid . "','" . $habitid . "','" . $minvalue . "','" . $maxvalue . "','" . $boolvalue . "','" . $generic . "')";

This gives me a SQL statement of:
INSERT INTO content_habitparameters (Content_ID, Habit_ID, Min_Value, Max_Value, yesorno, Section_Generic) VALUES ('6','38','','','0','1')

Whilst '' works fine in my dev environment it is no good for my production environment. How do I deal with this?

thanks

Options: ReplyQuote


Subject
Written By
Posted
submitting null value from php to MySql
October 29, 2020 01:46AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.