Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML form, set blank form to NULL
    text
    copied!<p>I have a HTML form; I want to be able to set it so that if a field is empty, the field in the DB will actually be NULL and not just have the word NULL in the field. I thought that using this code would help, but it just puts the word NULL in the field. PHP Code:</p> <pre><code>&lt;pre&gt; &lt;?php if (isset($_POST['oc_item'])) { $oc_item = mysql_escape_string($_POST['oc_item']); $oc_itemdesc = (!empty($_POST['oc_itemdesc'])) ? $_POST['oc_itemdesc'] : NULL; $sql = "INSERT INTO catalog_dev (oc_item,oc_itemdesc) VALUES(''$oc_item','$oc_itemdesc')"; mysql_query($SQL); if (mysql_query($sql)) { echo '&lt;strong&gt;&lt;em&gt;Your data has been submitted&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;'; } else { echo '&lt;p&gt;Error adding submitted info: ' . mysql_error(). '&lt;/p&gt;'; } } ?&gt;&lt;/pre&gt; </code></pre> <p>HTML Code:</p> <pre><code>&lt;pre&gt; &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Item Name&lt;/td&gt; &lt;td&gt;&lt;input class="forms" type="text" size="50" maxlength="50" name="oc_item" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Item Description&lt;/td&gt; &lt;td&gt;&lt;input class="forms" type="text" size="50" maxlength="50" name="oc_itemdesc" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt;&lt;input type="submit" value="Submit item" /&gt;&lt;/p&gt; &lt;/form&gt;&lt;/pre&gt; </code></pre> <p>I want the field to actually be <em>NULL</em> and not have the field contain the word NULL. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload