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 6358457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:22:38+00:00 2026-05-24T23:22:38+00:00

I am assigning a variable a numeric value or writing a NULL to it

  • 0

I am assigning a variable a numeric value or writing a NULL to it with an if statement, if it’s 0.00.

When writing to MySQL from my PHP page, I’m trying to pass this value and it always writes 0.00 for NULL. I’m guessing that’s because my insert statement is sending .$price. and it sees it as being in quotes?

If I echo $price before the insert, it shows me that it’s NULL but after the insert statement, it never remains.

How can I insert a NULL.. since I have to use a variable and send a value if there is one?

  • 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-05-24T23:22:39+00:00Added an answer on May 24, 2026 at 11:22 pm

    To insert NULL into your table, you acutally need to pass the string "NULL" into your query, rather than the PHP NULL value. A PHP NULL, if enclosed in single-quotes and passed to the query will be interpreted as a 0.

    // If $price is NULL in PHP, set it to the string "NULL"
    // Otherwise, set it to the current value of $price, but enclosed in single quotes as '$price'
    $price = $price === NULL ? "NULL" : "'$price'";
    
    // Then $price gets passed to your query either as NULL or as the single-quoted $price
    mysql_query("INSERT INTO tbl (price) VALUES ($price);");
    

    Of course, you have already called $price = mysql_real_escape_string($price); before this…

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

Sidebar

Related Questions

Trying to pass the variable flickrurl to a PHP page with jQuery/ajax. It works
I have a hidden input variable called str. I am assigning abc value to
From what I understand, when assigning a struct variable to another one, the first
For the very common case of assigning a value to a variable based on
I am trying to display error messages by assigning the SMARTY variable $error in
I'm assigning a variable string from an XML node and for some reason when
The main issue I'm thinking about is whether assigning a variable in an if
Assigning a Date variable to another one will copy the reference to the same
I am assigning ViewState[something] in Page Load of content page and when I try
I am assigning to an ImageView contacts images using this code: mPhotoView = (ImageView)

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.