无法更新数据库中的图像路径

时间:2014-11-06 12:11:13

标签: mysql

我无法在php中更新我的sql数据库中的图像路径。它也没有显示任何错误。我想设置用户的个人资料图片(如facebook),所以我已经完成了编码,但它不起作用,任何人都可以帮助我找到我的错误。

profilepicture.php

<!-- Step 3-->

<?php

<?php
/**********MYSQL Settings****************/
$host="localhost";
$databasename="photo_db";
$user="root";
$pass="";
/**********MYSQL Settings****************/
$conn=mysql_connect($host,$user,$pass);
if($conn)
{
	$db_selected = mysql_select_db($databasename, $conn);
	if (!$db_selected) 	
	{
		die ('Can\'t use foo : ' . mysql_error());
	}
}
else
{   	 die('Not connected : ' . mysql_error());
}




?>




    function GetImageExtension($imagetype)
     {
       if(empty($imagetype)) return false;

       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
		   default: return false;
		}
	}

	
	
	
if (!empty($_FILES["uploadedimage"]["name"]))
 {
    $file_name=$_FILES["uploadedimage"]["name"];
    $temp_name=$_FILES["uploadedimage"]["tmp_name"];
    $imgtype=$_FILES["uploadedimage"]["type"];
    $ext= GetImageExtension($imgtype);
	$imagename=$_FILES["uploadedimage"]["name"];
	//$imagename=date("y-d-m")."-".time().$ext;
    $target_path = "images/".$imagename;
	

     if(move_uploaded_file($temp_name, $target_path)) 
	 {
		
		
		$query_upload="UPDATE signup SET profilepicture='$target_path' WHERE uname='devansh@gmail.com' limit 1 " ;
		$qry=mysql_query($query_upload) or die("error in $query_upload == ".mysql_error()); 
		if(!$qry)
		{
			die("mySQL error: ". mysql_error());  
		}
		else
		{
			header("location:index.php");
		}
		     
	}
	 else
	 {
		exit("Error While uploading image on the server");
	 }
}
   ?>
index.html

<html>
  <head>
<script type="text/javascript">
function performClick(node)
{
	var evt = document.createEvent("MouseEvents");
	evt.initEvent("click", true, false);
	node.dispatchEvent(evt);
	var theFile = document.getElementById("theFile");
	// the file is the first element in the files property


}
</script>
 </head>
  <body>
    
      

      <a href="profilepicture.php" onclick="performClick(document.getElementById('theFile'));">Edit</a>
	
						<input type="file" id="theFile" name="uploadedimage"  style="visibility:hidden;" /> 
							
  </body>
 </html>

1 个答案:

答案 0 :(得分:1)

在sql字符串中添加一些空格:

    $query_upload="UPDATE signup".
    " SET profilepicture='$target_path'".
    " WHERE uname='devansh@gmail.com' limit 1 " ;

您的查询字符串生成:

UPDATE signupSET profilepicture=$target_pathWHERE uname='devansh@gmail.com' limit 1  ;

这应该会给你一个语法错误。