Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading Image to MYSQL DB using PHP
    primarykey
    data
    text
    <p>yet another PHP question which I am stuck on, so here is what im trying to do and my code:</p> <p><strong>Step one</strong> - 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.</p> <p><strong>What is working?</strong> *<em>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</em>*</p> <p><strong>Edits here</strong> -Realised that Id field, favname field, are not recording any information, and link is not uploading to the folder correctly.</p> <p>Any help would be much appreciated: Here goes.</p> <p>SecondPic.php</p> <pre><code>&lt;?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 &lt;br&gt;&lt;a href=index.php&gt; return to index &lt;/a&gt;\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); ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>SecondUpload.php</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form enctype="multipart/form-data" id="form1" name="form1" method="post" action="secondPic.php"&gt; &lt;p&gt; &lt;label for="name1"&gt;Fav Location Name: &lt;/label&gt; &lt;input type="text" name="fav1" id="fav1" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="photo1"&gt;Fav Location Photo: &lt;/label&gt; &lt;input type="file" name="photo1"&gt;&lt;br&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="formID"&gt;ID: &lt;? echo $rows['id']; ?&gt; &lt;/label&gt; &lt;input name="id" type="hidden" id="id" value="&lt;? echo $rows['id']; ?&gt;"&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" name="submit" id="submit" value="Submit" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload