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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:15:32+00:00 2026-06-08T21:15:32+00:00

So I have this script that takes a bunch of json files and sends

  • 0

So I have this script that takes a bunch of json files and sends them to my database. The script works fine for 8777 of the files, but for 70 of the files I get the following mysql syntax error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Shea', '', '190', '1981-4-30', 'Right', '106', '13', '25', '65', '39', '64', '61' at line 1

Here is the loop I am using, and I apologize for the long query:

For($id=1; $id<=205600; $id++)
{
if (file_exists('data/players/'.$id.'.json'))
    {
        //read json file
        $json_file = file_get_contents('data/players/'.$id.'.json');
        $file_data = json_decode($json_file, true);

        //my super long query
        $query =  'INSERT INTO `db`.`table` (`id`, `first_name`, `last_name`, `common_name`, `height`, `dob`, `foot`, `club_id`, `league_id`, `nation_id`, `attribute1`, `attribute2`, `attribute3`, `attribute4`, `attribute5`, `attribute6`, `rare`, `rating`, `type`) VALUES (\''.$id.'\', \''.$file_data['Player']['FirstName'].'\', \''.$file_data['Player']['LastName'].'\', \''.$file_data['Player']['CommonName'].'\', \''.$file_data['Player']['Height'].'\', \''.$dob.'\', \''.$file_data['Player']['PreferredFoot'].'\', \''.$file_data['Player']['ClubId'].'\', \''.$file_data['Player']['LeagueId'].'\', \''.$file_data['Player']['NationId'].'\', \''.$file_data['Player']['Attribute1'].'\', \''.$file_data['Player']['Attribute2'].'\', \''.$file_data['Player']['Attribute3'].'\', \''.$file_data['Player']['Attribute4'].'\', \''.$file_data['Player']['Attribute5'].'\', \''.$file_data['Player']['Attribute6'].'\', \''.$file_data['Player']['Rare'].'\', \''.$file_data['Player']['Rating'].'\', \''.$file_data['Player']['ItemType'].'\');';
        mysql_query($query);

        //record loop status
        if (mysql_error())
        {
            $error = mysql_error();
            echo $error.'<br/>';
            $errors ++;
        }
        else
        {
            $entries ++;
        }
    }
}

So how can I resolve this error?

  • 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-08T21:15:34+00:00Added an answer on June 8, 2026 at 9:15 pm

    Escaping your SQL would go a long way towards fixing this.

    If you’re using this in production you’re lucky you have that many successful transactions.

    A fixed up example looks more like this:

    $dbh = new PDO(...);
    
    $stmt = $dbh->prepare('INSERT INTO `db`.`table` (`id`, `first_name`, `last_name`, ...)
      VALUES (:id, :Player_FirstName, :Player_LastName, ...)');
    $stmt->bindParam(':id', $id);
    $stmt->bindParam(':Player_FirstName', $file_data['Player']['FirstName']);
    $stmt->bindParam(':Player_LastName', $file_data['Player']['LastName']);
    // ... Etc...
    
    // insert one row
    $stmt->execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script that works, but I need to change the format of
I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I have this small PHP script that takes a POST variable and writes it
I have this script set up that echoes all relevant users in a database
I have a simple script that will send out a bunch of emails but
I have written a script that goes through a bunch of files and snips
Right now I have a Phing script that takes the files from a branch
I have this beautiful jquery script that takes list of li s and groups
I have this script that run to fix my menu bar to the browser
I have this script that collects data from users and I want to check

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.