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

  • Home
  • SEARCH
  • 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 4324112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:05:18+00:00 2026-05-21T09:05:18+00:00

My page sends using ajax data to a php script. one of the vars

  • 0

My page sends using ajax data to a php script. one of the vars that the script gets is: $product_disc
now a small test that I have done inside the script clearly revealed that $product_disc is null. the test:

if ($product_disc == null)
 {$test="null";}
 else {$test="not null";}

I make my code return $test to the ajax calling procedure:

$return_array['success'] = array ('test' => $test);

And using Firebug I see that the ajax response has: “test”:”null”
So i conclude that $product_disc is of value: null

Now, inside my script I’m using the following code to insert data to MySql DB:

$stmt = mysqli_prepare($link, "INSERT INTO set_products (id,discount) VALUES (NULL , ?)");
mysqli_stmt_bind_param($stmt, "i", $product_disc);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);

The query is being executed, but the value that was inserted is 0 and not NULL!
Only when I explicitly added: $product_disc=null; before the MySqli statements, the value that was inserted was NULL.

Why is that? What’s the different between a null and a null? I followed this answer in stackoverflow hoping that i could easily insert NULLs but then came this problem…

Thank you!

PS @stackoverflow team – Your spell checking dictionary doesn’t recognize the word stackoverflow!

  • 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-21T09:05:19+00:00Added an answer on May 21, 2026 at 9:05 am

    You prepare product_disc as integer, null is not an integer. It is converted to 0.

    While preparing as a string, would definitely fix your issue, it defeats the purpose of preparing a mysql statement. Consider this solution:

    mysqli_stmt_bind_param($stmt, $product_disc==null?'s':'i', $product_disc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I finally succeeded in using Ajax to get SOMETHING sent from one page to
Im using Ajax to send values to a PHP script which writes some value
I am using php/ajax to submit a form without page refresh. Here are my
I am using jquery to post vars to a php script. Is it possible
I am using php/ajax to submit a form without page refresh. Here are my
I am using Jquery AJAX to post a form on my page. I want
I have a problem using AJAX. The 2 functions that are called via the
I'm using CKEditor to created the portion of my CMS for the user to
I have a very simple class using HttpListener to receive an HTTP POST from
Wikipedia provides information about one of the most common scenarios for exploiting a reflected

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.