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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:55:27+00:00 2026-06-13T09:55:27+00:00

Hey Guys I have a big problem that I have no Idea why.. I

  • 0

Hey Guys I have a big problem that I have no Idea why..
I have few forms that upload files to the database, all of them work fine except one.. I use the same query in all(simple insert). I think that it has something to do with the files i am trying to upload but I am not sure.

Here is the code:

if ($_POST['action'] == 'hndlDocs') {
$ref = $_POST['reference']; // Numeric value of
$doc = file_get_contents($_FILES['doc']['tmp_name']);


$link = mysqli_connect('localhost','XXXXX','XXXXX','documents');
mysqli_query($link,"SET autocommit = 0");

$query = "INSERT INTO documents ({$ref},
'{$doc}',
'{$_FILES['doc']['type']}')
;";
mysqli_query($link,$query);
if (mysqli_error($link)) {
    var_dump(mysqli_error($link));
    mysqli_rollback($link);
} else {
    print("<script> window.history.back(); </script>");
    mysqli_commit($link);
}

}

The database has only these fields:

DATABASE documents (
    reference INT(5) NOT NULL, //it is unsigned zerofill
    doc LONGBLOB NOT NULL, //this should contain the binary data
    mime_type TEXT NOT NULL // the mime type of the file php allows only application/pdf and image/jpeg
);

And the error I get is :

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 '00001, '����' at line 1

UPDATE:

Except that I have forgotten to add the VALUE in the SQL query.
I have to add addslashes() to the content that is collected from the file and it is all done.

I will appreciate every help.
Cheers!

  • 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-13T09:55:28+00:00Added an answer on June 13, 2026 at 9:55 am

    You forgot to add VALUES keyword. The type of INSERT syntax you use is implicit. So it is assumed that you table has only 3 columns because you have supplied only 3 values. But if you have more than 3 columns, then you need to explicitly define the columns names in your query.

    $query = "INSERT INTO documents VALUES ({$ref}, 
                                           '{$doc}', 
                                           '{$_FILES['doc']['type']}');";
    

    your query is vulnerable with SQL Injection. Please take time to read the article below

    • Best way to prevent SQL injection in PHP?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey Guys, i have a big problem with my jQuery Datepicker Script. I use
Hey guys I have a few image views that I am using several times
Hey guys i have a problem. I have a listview that is dynamically filled.
Hey guys I have an admin page that checks if you are admin before
Hey guys I have one more question lol. I am using a script that
Hey guys I have a query that currently finds the latest comment for each
hey guys having this really simple problem but cant seem to figure out have
Hey guys, I have a raidan style 2d flying/fighter game that im working on.
Hey guys I have an array of dictionaries plist file that I am reading
Hey guys I have a query that selects data and organizes but not in

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.