Note that there are some explanatory texts on larger screens.

plurals
  1. POSql Query Not Updating The Path Of Img File
    primarykey
    data
    text
    <p>There isn't a singlle tutorial on how to upload image file through file syste and save its path in sql database. And its mentioned on some sites but no explained properly. Nyway I am uploading an image through php and i want to store the path of the uploaded image in the sql database. I have 2 pages </p> <p>1.) insert.php</p> <pre><code>&lt;?php session_start(); if (!isset($_SESSION["MM_Username"])) { $_SESSION["message"] = "Please Login"; } ?&gt; &lt;!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" --&gt; &lt;form name="newad" method="post" enctype="multipart/form-data" action="chkupload.php"&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;&lt;input type="file" name="image"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;input name="Submit" type="submit" value="Upload image"&gt; &lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>this page works absolutely fine but the problem is in the next file</p> <p>2)chkupload.php</p> <p>The problem is that the upload works fine &amp; It creates the file in the images/ folder but does not save the path of it in the sql table. So basically i need help with this. Also its under user authentication. Its a profile picture.</p> <pre><code> &lt;?php require_once('Connections/mb.php'); $loginUsername = $_SESSION['MM_Username']; //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","100"); //This function reads the extension of the file. It is used to determine if the // file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no // error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and // will not upload the file, //otherwise we will do more tests if (($extension != "jpg") &amp;&amp; ($extension != "jpeg") &amp;&amp; ($extension != "png") &amp;&amp; ($extension != "gif")) { //print error message echo '&lt;h1&gt;Unknown extension!&lt;/h1&gt;'; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size &gt; MAX_SIZE*1024) { echo '&lt;h1&gt;You have exceeded the size limit!&lt;/h1&gt;'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images //folder) $newname="images/".$image_name; //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '&lt;h1&gt;Copy unsuccessfull!&lt;/h1&gt;'; $errors=1; }}}} //If no errors registred, print the success message if(isset($_POST['Submit']) &amp;&amp; !$errors) { echo "&lt;h1&gt;File Uploaded Successfully! Try again!&lt;/h1&gt;"; } mysql_connect("localhost", "root", "") or die(mysql_error()); echo "Connected to MySQL&lt;br /&gt;"; mysql_select_db("musibridge") or die(mysql_error()); echo "Connected to Database"; $result = mysql_query("UPDATE artist92 SET path= $newname WHERE email = $loginUsername") or die(mysql_error()); ?&gt; </code></pre> <p>The error generated is</p> <p>Notice: Undefined variable: _SESSION in C:\xampp\htdocs\MB\chkupload.php on line 3 File Uploaded Successfully! Try again! Connected to MySQL Connected to DatabaseYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'jpg WHERE email =' at line 1</p> <p>Please help me fix this. Its uploading but not updating the column path of the table artist92</p> <p>This is my login page.Adding it just for your reference for session variable artlog.php</p> <pre><code> &lt;?php require_once('Connections/mb.php'); ?&gt; &lt;?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION &lt; 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_Recordsetartist = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_Recordsetartist = $_SESSION['MM_Username']; } mysql_select_db($database_mb, $mb); $query_Recordsetartist = sprintf("SELECT * FROM artist92 WHERE email = %s", GetSQLValueString($colname_Recordsetartist, "text")); $Recordsetartist = mysql_query($query_Recordsetartist, $mb) or die(mysql_error()); $row_Recordsetartist = mysql_fetch_assoc($Recordsetartist); $totalRows_Recordsetartist = mysql_num_rows($Recordsetartist); $query_Recordsetartist = "SELECT * FROM artist92"; $Recordsetartist = mysql_query($query_Recordsetartist, $mb) or die(mysql_error()); $row_Recordsetartist = mysql_fetch_assoc($Recordsetartist); $totalRows_Recordsetartist = mysql_num_rows($Recordsetartist); $colname_Recordsetartist = "-1"; if (isset($_SESSION['MM_email'])) { $colname_Recordsetartist = $_SESSION['MM_email']; } mysql_select_db($database_mb, $mb); $query_Recordsetartist = sprintf("SELECT * FROM artist92 WHERE email = %s", GetSQLValueString($colname_Recordsetartist, "text")); $Recordsetartist = mysql_query($query_Recordsetartist, $mb) or die(mysql_error()); $row_Recordsetartist = mysql_fetch_assoc($Recordsetartist); $colname_Recordsetartist = "-1"; if (isset($_SESSION['MM_email'])) { $colname_Recordsetartist = $_SESSION['MM_email']; } mysql_select_db($database_mb, $mb); $query_Recordsetartist = sprintf("SELECT * FROM artist92 WHERE email = %s", GetSQLValueString($colname_Recordsetartist, "text")); $Recordsetartist = mysql_query($query_Recordsetartist, $mb) or die(mysql_error()); $row_Recordsetartist = mysql_fetch_assoc($Recordsetartist); ?&gt; &lt;?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['email'])) { $loginUsername=$_POST['email']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "artistprofile.php"; $MM_redirectLoginFailed = "artlog.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_mb, $mb); $LoginRS__query=sprintf("SELECT email, password FROM artist92 WHERE email=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $mb) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; if (PHP_VERSION &gt;= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();} //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) &amp;&amp; false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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