Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP image upload not working
    primarykey
    data
    text
    <p>I'm just trying to upload an image and insert its location into database(SQLYog). The code works fine without database connection. But when I try to link it with SQL Yog , action page displays nothing at all and nothing is getting inserted into database table. It would be great if you could help. Here goes my code.</p> <p><strong>form.php</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function validate(){ var filevalue=document.getElementById("file").value; var description=document.getElementById("description").value; if(filevalue=="" || filevalue.length&lt;1){ alert("Select File."); document.getElementById("file").focus(); return false; } if(description=="" || description.length&lt;1){ alert("File Description must not be blank."); document.getElementById("description").focus(); return false; } return true; } &lt;/script&gt; &lt;/head&gt; &lt;body &gt; &lt;h2 align="center" &gt;File Upload&lt;/h2&gt; &lt;form action="file_upload.php" method="post" enctype="multipart/form-data" onSubmit="return validate()" &gt; &lt;table align="center" &gt; &lt;tr&gt; &lt;td&gt;&lt;label for="file"&gt;File:&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="file" name="file" id="file" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;label &gt;File Description:&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="description" id="description" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>file_upload.php</strong></p> <pre><code>&lt;?php include("connect.php"); //database connection if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) &amp;&amp; ($_FILES["file"]["size"] &lt; 1000000)) { if ($_FILES["file"]["error"] &gt; 0) { echo "File Error : " . $_FILES["file"]["error"] . "&lt;br /&gt;"; } else { echo "Upload File Name: " . $_FILES["file"]["name"] . "&lt;br /&gt;"; echo "File Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;"; echo "File Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;"; echo "File Description:: ".$_POST['description']."&lt;br /&gt;"; if (file_exists("images/".$_FILES["file"]["name"])) { echo "&lt;b&gt;".$_FILES["file"]["name"] . " already exists. &lt;/b&gt;"; }else { move_uploaded_file($_FILES["file"]["tmp_name"],"images/". $_FILES["file"]["name"]); $loc="images/".$_FILES["file"]["name"]; $qu="insert into images.img(loc) values('$loc')"; mysql_query($qu,$con); ?&gt; Uploaded File:&lt;br&gt; &lt;img src="images/&lt;?php echo $_FILES["file"]["name"]; ?&gt;" alt="Image path Invalid" &gt; &lt;?php } } }else { echo "Invalid file detail ::&lt;br&gt; file type ::".$_FILES["file"]["type"]." , file size::: ".$_FILES["file"]["size"]; } ?&gt; </code></pre> <ul> <li>Database name: image</li> <li>Table name : img </li> <li>Table fields : imgid(int primary key, auto incr) , loc(varchar)</li> </ul>
    singulars
    1. This table or related slice is empty.
    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.
    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