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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:34:56+00:00 2026-06-12T22:34:56+00:00

Basically I have written a script to allow the user in the back end

  • 0

Basically I have written a script to allow the user in the back end to upload pictures for the gallery. The script is supposed to upload the file to the server and then post the file name and info into the database.

It always uploads the file to the server without fail, however for some reason it only posts it to the database occasionally. Sometimes it works fine but 8 times out of 10 it uploads the file and thats it, the script is as follows.

<?php  

 //This is the directory where images will be saved  
 $target = "images/";  
 $target = $target . basename( $_FILES['photo']['name']);  

 //This gets all the other information from the form  
 $name=$_POST['name'];  
 $caption=$_POST['caption'];  
 $pic=($_FILES['photo']['name']);  
 $live=$_POST['live']; 

 //Connecting to the database 
 require_once('../Connections/tim.php');  


 //Writes the information to the database  
 mysql_query("INSERT INTO `gallery` VALUES ('$name', '$caption', '$pic', '$live')") ;  

 //Writes the photo to the server  
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))  
 {  

 //Tells you if its all ok  
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded successfully, press back to upload more";  
 }  
 else {  

 //Gives and error if its not  
 echo "Sorry, there was a problem uploading your file.";  
 }  
 ?>  
  • 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-12T22:34:57+00:00Added an answer on June 12, 2026 at 10:34 pm

    You really should read something on SQL Injection and you should use PDO or mysqli (as jeroen) suggested.

    But debugging at your situation could be done by this:

    mysql_query("INSERT INTO `gallery` VALUES ('$name', '$caption', '$pic', '$live')") ;  
    if( mysql_errno() != 0){
         // mysql error
         // note: message like this should never appear to user, should be only stored in log
         echo "Mysql error: " . htmlspecialchars( mysql_error());
         die();
    }
    

    And you have to escape your database inputs at least by mysql_real_escape_string().

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

Sidebar

Related Questions

I have written a script which is basically a small wysiwyg signature generator for
I have written a simple shell script to do some automation work. Basically the
Basically I have written an AJAX script using pure javascript and I have a
I have written a custom class for overriding the seek method of QSlider. Basically
I have a custom component called ButtonPanel written in Actionscript. Basically it's just a
I basically have a program that filters records from one excel file to another
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I have written a script. It does work! It's just a bit rubbish. Could
So I have a text file which has the script of Act 1 from
I have this bash script on the server that runs every hour, via cron.

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.