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

The Archive Base Latest Questions

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

Im working with a mysql database via php. I have a table with some

  • 0

Im working with a mysql database via php.

I have a table with some values that are = NULL

I select these values in php:

$opponentInv = db_execute("Select * from inventoryon where playerid = ".$defendid.";");
$opponentInv = mysql_fetch_assoc($opponentInv);

Then i insert the values into a another table:

db_execute("INSERT INTO `inventoryCombat` (`attackid` ,`defendid` ,`money` ,`item1` ,`item2` ,`item3`, `item4` ,`item5` ,`item6`, `time`)VALUES ('".$attackid."', '".$defendid."', '".$opponentInv["money"]."', '".$opponentInv["item1"]."', '".$opponentInv["item2"]."', '".$opponentInv["item3"]."', '".$opponentInv["item4"]."', '".$opponentInv["item5"]."', '".$opponentInv["item6"]."', '".$time."');");

The issue is that when i insert the values into the second table, they are always coming out as 0. The values in the inventoryCombat table are 0 when they should be NULL (what they are in the inventoryon table). The table is set to accept NULL as values.

  • 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-18T04:21:31+00:00Added an answer on May 18, 2026 at 4:21 am

    Firstly I’d strongly recommend that you use prepared statements instead of building a literal SQL string. Not only is this a better practice and helps you to write a more secure application, it also handles NULL values correctly without requiring any extra work.

    If you want to continue using the method you are currently using then you will need to explicitly check for undefined values and insert the string ‘NULL’ into your SQL. In other words, you need to do this:

    INSERT INTO inventoryCombat (item1) VALUES (NULL);
    

    Instead of what you are currently doing:

    INSERT INTO inventoryCombat (item1) VALUES ('');
    

    If it still doesn’t work, double-check that the field you are trying to insert NULL into is set to allow NULL values. You can use SHOW CREATE TABLE inventoryCombat to do this.

    I’d also recommend normalizing your database. Having columns called item1, item2, item3 etc. is a sign of a bad design. Your current design will, for example, make it more complicated to perform what should be simple queries such as ‘How many players possess item X?’ or ‘Add item X to player P unless she is already holding 6 items’.

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

Sidebar

Related Questions

I'm currently working on a PHP application that uses a MySQL database for its
I have a java program that connects to a MySql database and it's working
I am working on PHP and database MySQL. I have two tables in SQL
I'm working on an application that stores user inputs into the database table via
I am working on a MySQL database that is huge (about 120 tables). I
I'm working with PHP and MySQL, and I'm not too experienced with database design.
I'm working on a MYSQL/PHP system where I have the following: -- a set
I am working with a rather large mysql database (several million rows) with a
I am working on a localhost app which is backed by a MySQL database.
I'm working on a colorpicker. My idea is to update a MySQL database thru

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.