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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:07:33+00:00 2026-05-28T22:07:33+00:00

yet another PHP question which I am stuck on, so here is what im

  • 0

yet another PHP question which I am stuck on, so here is what im trying to do and my code:

Step one – Attempting to upload a Name, Image and ID to a SQL Table. The table is called second and has 4 fields. I am using one of the fields as a FK from another table called admin and the FK is id.

What is working?
*When i click the submit button, the link of the image gets uploaded, but physically no image within my folder. When trying to upload the form I am wanting to use the ID of the user and put that into the new table so i can refer to that field to display the data. I feel like this is a hard scenario to explain*

Edits here
-Realised that Id field, favname field, are not recording any information, and link is not uploading to the folder correctly.

Any help would be much appreciated: Here goes.

SecondPic.php

<?php
include "common.php";
$secondid = $_GET['id'];
DBConnect();



$Link = mysql_connect($Host, $User, $Password);

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


$favname = $_POST["name1"];
$pic2=($_FILES['photo1']['name']); 
$id = $_POST["$formID"];



$Query ="INSERT into $Table_2 values ('0', '$id', '$favname', '$pic2')";

if (mysql_db_query ($DBName, $Query, $Link)){
print ("A record was created <br><a href=index.php> return to index </a>\n");

 // Connects to your Database 
 //mysql_connect("localhost", "jonathon_admin", "hello123") or die(mysql_error()) ; 
 //mysql_select_db("jonathon_admin1") or die(mysql_error()) ; 


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

 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 

 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 


} else {

print (" - Your Record was not created");   
}

mysql_close($Link);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

SecondUpload.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form enctype="multipart/form-data" id="form1" name="form1" method="post" action="secondPic.php">
  <p>
    <label for="name1">Fav Location Name: </label>
  <input type="text" name="fav1" id="fav1" />
  </p>
  <p>
  <label for="photo1">Fav Location Photo: </label>
 <input type="file" name="photo1"><br> 
  </p>
  <p>
  <label for="formID">ID: <? echo $rows['id']; ?> </label>
  <input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
  </p>
  <p>
    <input type="submit" name="submit" id="submit" value="Submit" />
  </p>
</form>



</body>
</html>
  • 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-05-28T22:07:33+00:00Added an answer on May 28, 2026 at 10:07 pm

    Aftr Looking at your post in it’s entirety, the title has mislead me (and probably the guy above) into think you wanted to store the image data directly into the database.

    That is not what you want to do.

    Here are my questions for you before we proceed.

    $target = "second/"
    

    Is this script “SecondPic.php” in the base folder? And the folder “second” in the same base folder?

    Generally it’s better to give an absolute path in move_uploaded_file(), so $target should be something like:

    $target = dirname(__FILE__) . DIRECTORY_SEPARATOR . $_FILES['photo1']['name'];
    

    Secondly, it’s better to move the file before saving to database, because moving the file has a higher chance of erroring out.

    Thirdly, any errors? in log or output of page?

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

Sidebar

Related Questions

Here goes a yet another SQL question about dates… I'm building a calendaring application
I am trying to create a file with PHP here is my code: $file_to_send
After getting a helpful answer here , I have run into yet another problem:
I guess this question will sound familiar, but I am yet another programmer baffled
Another slightly non-technical question, but I couldn't decide whether to ask here or on
I posted a question before but I am yet limited to mix the code
this is yet another .htaccess question. And I already did my literature review. Would
I'm trying to create an exact duplicate of another table via php by using
I have yet another question regarding the randomization of data! $gender=''; if(isset($_GET['gender'])) { $gender=$_GET['gender'];
I am about to embark upon yet another large PHP project. This time, I

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.