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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:22:04+00:00 2026-06-14T10:22:04+00:00

Im working on grabbing xml data from ebay and putting the results into MySQL,

  • 0

Im working on grabbing xml data from ebay and putting the results into MySQL, Grabbing the data works fine, however inputting to database fails due to an incorrect integer value for a couple of the xml tags values.

The xml tag value is the word “true” (without the quotes), and this is the db sql:

CREATE TABLE ebay_categories (
CategoryID int(10) NOT NULL default '0',
CategoryLevel int(5) NOT NULL default '0',
CategoryName varchar(120) NOT NULL default '',
CategoryParentID int(10) NOT NULL default '0',
LeafCategory int(1) NOT NULL default '0',
AutoPayEnabled int(1) NOT NULL default '0',
Expired int(1) NOT NULL default '0',
IntlAutosFixedCat int(1) NOT NULL default '0',
Virtual int(1) NOT NULL default '0',
LSD int(1) NOT NULL default '0',
ORPA int(1) NOT NULL default '0',
PRIMARY KEY  (CategoryID),
KEY catlevel (CategoryLevel),
KEY parent (CategoryParentID),
KEY ape (AutoPayEnabled),
KEY expired (Expired),
KEY IAFC (IntlAutosFixedCat),
KEY virtual (Virtual),
KEY lsd (LSD),
KEY orpa (ORPA),
KEY leaf (LeafCategory)
) TYPE=MyISAM; 

i have tried int, tinyint, Boolean (resorts to tinyint) to no avail and still get this issue. Theres nothing wrong with the db connection as i ran a test using varchar as the int type for the LeafCategory and others and everything worked ok.

is theres something i can do without resorting to searching and replacing via regex before db insertion?

edit:

    $query = "INSERT INTO `ebay_categories` (`CategoryID`, `LeafCategory`)VALUES           ('$xmlCategoryID', '$xmlLeafCategory')";

    if (mysqli_query($link, $query)) {
    echo "Successfully inserted " . mysqli_affected_rows($link) . " row";
} else {
    echo "Error occurred: " . mysqli_error($link);
}

The SQL statement unwrapped from client code is:

    INSERT INTO `ebay_categories` 
                (`CategoryID`, `LeafCategory`)
         VALUES 
                ('$xmlCategoryID', '$xmlLeafCategory')";
  • 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-14T10:22:05+00:00Added an answer on June 14, 2026 at 10:22 am

    The error you have is telling you at least one record in your XML has something other than a valid integer for either $xmlCategoryID or $xmlLeafCategory.

    What to do?

    A. You could have your error message display the offending data, something like this:

      echo "Error occurred: " . mysqli_error($link);
      echo "Bad data was either ##$xmlCategoryID## or ##$xmlLeafCategory##.";
    

    Notice that I used ##$value## so you can detect empty strings in your error messages. You probably should do this.

    B. You could try changing your column definitions for those columns to remove the NOT NULL declaration. If in fact one of those values is empty, this may fix your problem.

    C. It’s possible that you need bigint values for this information. That is, they could be very large numbers.

    D. If you don’t care enough about null or bad values to bother to detect them you could try this.

    INSERT INTO `ebay_categories` 
                 (`CategoryID`, `LeafCategory`)
          VALUES 
                 (CAST(IFNULL('$xmlCategoryID',-1) AS INT)
                (CAST(IFNULL('$xmlLeafCategory',-1) AS INT)
    

    This will turn null values into -1 and non-integer values into 0.

    Edit: Oh, I understand now. Your leafCategory item isn’t a number in XML, it’s a true/false/empty value. Presumably false and empty mean the same thing.

    Try this, using a SQL case statement to translate true/other to 1/0.

    INSERT INTO `ebay_categories` 
                 (`CategoryID`, `LeafCategory`)
          VALUES (
                  '$xmlCategoryID',
                  CASE '$xmlLeafCategory' WHEN 'true' THEN 1 ELSE 0 END
                  )
    

    Finally, danger! You need to use prepared statements, and you need to sanitize these values you’re extracting from your XML file. If you don’t somebody will be able to trick your software into destroying your database by feeding it a poisoned XML file. Please read up on SQL injection.

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

Sidebar

Related Questions

I am working on doing some data transfers moving data from one database to
I have this XML file from which I'm grabbing all the data: <?xml version=1.0
Im having trouble working grabbing a dynamically created image from this service: http://opsin.ch.cam.ac.uk/opsin/USER-STRUCTURE-TO-GENERATE.png Im
I'm working on an application that needs to accept posted data from a form
I've been working for a couple of days on grabbing frames from a phonon
i am working on a little script grabbing some files from a website. First
I'm grabbing data from a published google spreadsheet, and all I want is the
i m grabbing image paths from MySQL via php and then json_encode and with
I'm still working on the whole gathering user data from a visit thing, so
i have a rails controller grabbing some data from mongodb. the field i'm interested

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.