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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:19:03+00:00 2026-06-14T01:19:03+00:00

Ok so I have a script that takes data from a form inserts into

  • 0

Ok so I have a script that takes data from a form inserts into database and uploads the picture, its inserting all the information into the database but not uploading the picture.

The code is below, I am quite new to PHP so your advice is greatly appreciated.

Thank you 🙂

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

 //This gets all the other information from the form 
 $rest_name=$_POST['rest_name']; 
 $address1=$_POST['address1']; 
 $address2=$_POST['address2']; 
 $town=$_POST['town']; 
 $postcode=$_POST['postcode'];
 $open_time=$_POST['open_time']; 
 $halal=$_POST['halal'];
 $deliver_areas=$_POST['deliver_areas'];
 $deliver_time=$_POST['deliver_time'];
 $type=$_POST['type'];    
 $photo=($_FILES['photo']); 


  mysql_select_db(restaurants);


 //Writes the information to the database 
    mysql_query("INSERT INTO `restaurants` VALUES ('', '$rest_name', '$address1', '$address2', '$town', '$postcode', '$open_time', '$halal', '$deliver_areas', '$deliver_time', '$type', '$photo')") ;  
    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();
}

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

 { 


 //Tells you if its all ok 
header('Location: add-restaurant.php?added');
 } 
 else { 

 //Gives and error if its not 
header('Location: add-restaurant.php?fail');
 } 
  • 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-14T01:19:05+00:00Added an answer on June 14, 2026 at 1:19 am

    Use following code. Hope it will help you.

    if ($_FILES["photo"]["size"] < 30000) // specify file size here file size 
    {
      if ($_FILES["photo"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["photo"]["error"] . "<br />";
    }
    else
    {
    
    if (file_exists("../restaurants/images/" . $_FILES["photo"]["name"]))
      {
      echo $_FILES["photo"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["photo"]["tmp_name"],"../restaurants/images/" . $_FILES["photo"]["name"]);     
    $rest_name=$_POST['rest_name']; 
    $address1=$_POST['address1']; 
    $address2=$_POST['address2']; 
    $town=$_POST['town']; 
    $postcode=$_POST['postcode'];
    $open_time=$_POST['open_time']; 
    $halal=$_POST['halal'];
    $deliver_areas=$_POST['deliver_areas'];
    $deliver_time=$_POST['deliver_time'];
    $type=$_POST['type'];  
    $photo=$_FILES["photo"]["name"]  ;  
    
    
    
    
    mysql_select_db(restaurants);
    //Writes the information to the database 
    mysql_query("INSERT INTO `restaurants` VALUES ('', '$rest_name', '$address1', '$address2', '$town', '$postcode', '$open_time', '$halal', '$deliver_areas', '$deliver_time', '$type', '$photo')") ;  
    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();
    
    }
    
    
      }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically I have a PHP script that takes all the images from the
I have a Perl script that takes text values from a MySQL table and
In one of our applications, we have a script dump data from a database
I have this code that takes info from a form and sends it to
I have a script that takes a while. I'd like to display a page
I have a Perl script that takes user input and creates another script that
I have a script test.R that takes arguments arg1 , arg2 and outputs a
I have to create a script that takes a mySQL table, and exports it
I have this small PHP script that takes a POST variable and writes it
I currently have a script that deletes old log files and then takes any

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.