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>