Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Upload Image Path in SQL database
    text
    copied!<p>I have receive certain advices of inserting Image Path into the database instead of Image File itself. But i still have problem cause it does not work at all. May I know how should my SQL table be set if my code is like this? And please do point out my mistakes too.</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;?php session_start(); $dbhost = 'localhost'; $dbuser = 'root'; $dbpassword = ''; $dbconnect = mysql_connect($dbhost, $dbuser, $dbpassword) or die("gg"); $dbselect = mysql_select_db('uploadimg', $dbconnect) or die("gg1"); mysql_close($dbconnect); ?&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;Upload Image Path Into SQL Database&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php //getting the filename of the image file. $filename = $_FILES["image"]["name"]; //directory name to be stored. $path = "C:/xampp/htdocs/Test/images"; //uploading the image file with the image file name into the directory. if(move_uploaded_file($_FILES["image"]["tmp_name"],$path."/".$filename)) { //if the image is stored success into the directory then we are going to store into database. //the real path with the filename. $mysql_path = $path."/".$filename; //sql query to be executed. $sql = "INSERT INTO uploadimg(filename,path) VALUES ('$filename','$mysql_path')"; //executing the query. if(mysql_query($sql)) { echo 'path inserted into database'; } else { echo 'path not inserted into database'; } } else { echo 'file not uploaded'; } } ?&gt; &lt;form method="POST" enctype="multipart/form-data"&gt; File: &lt;input type="file" name="image"&gt; &lt;input type="submit" value="Upload" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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