Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:48:23+00:00 2026-06-06T17:48:23+00:00

I have a HTML form; I want to be able to set it so

  • 0

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:

<pre>
<?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 '<strong><em>Your data has been submitted</em></strong><br /><br />';
                } else {
            echo '<p>Error adding submitted info: ' . mysql_error(). '</p>';
        }
        }
        ?></pre>

HTML Code:

<pre>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

        <table>
        <tr>
            <td>Item Name</td>
            <td><input class="forms" type="text" size="50" maxlength="50" name="oc_item" /></td>
        </tr>
        <tr>
            <td>Item Description</td>
            <td><input class="forms" type="text" size="50" maxlength="50" name="oc_itemdesc" /></td>
        </tr>
</table>

        <p><input type="submit" value="Submit item" /></p>
        </form></pre>

I want the field to actually be NULL and not have the field contain the word NULL. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:48:24+00:00Added an answer on June 6, 2026 at 5:48 pm

    If you want to write NULL to a MySQL database, you really have to put NULL there without quotation marks.

    Like this:

    INSERT INTO table (column, column2) VALUES ('mystring', NULL);
    

    It’s always a bit effort if you want to do this manually by hand, because you would have to make if-conditions for the query.

    Remember: PHP null != MySQL NULL. They both do not know each other at all.

    But I am still wondering, what does that all have to do with the question name? (SELECT unless)

    You could write your code like this:

    $oc_item = mysql_escape_string($_POST['oc_item']);
    $oc_itemdesc = (isset($_POST['oc_itemdesc']) && trim($_POST['oc_itemdesc']) != '') ? "'" . mysql_escape_string($_POST['oc_itemdesc']) . "'" : 'NULL';
    
    $sql = "INSERT INTO catalog_dev (oc_item,oc_itemdesc)
            VALUES('" . $oc_item . "', " . $oc_itemdesc . ")";
    # sorry for adding " . all the time, but I dislike variables within strings :D
    

    But I have to admit I do not like that much either, as it moves the duty to wrap quotation marks around MySQL strings away from the SQL-query itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html form with no submit button. I want to submit that
I have a html form that I process with a aspx page. I want
I have a Html form. I want to get the file containing posted form's
Suppose you're building an HTML form and you want to have 2 or more
I have a following problem, I have HTML form that uploads a file with
I have an HTML form that takes inputted data and sends it via the
We have some html that looks like this: <form id=MyUserControl runat=server method=post> <script language=javascript
I want to be able to convert a html form to an ExtJs form.
I have custom Question objects which I render into html form elements. I want
Ok so in my html/js i have a form that updates based on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.