dongli7236 2014-02-24 12:44
浏览 44
已采纳

PHP表单不上传照片到Web文件夹或MSSQL表列

I have a form that is supposed to allow the user to upload an image that will have it's file saved into the folder unitimages and it's filename saved into my MSSQL table column photo in the table used_trailers1. So far, when I hit submit on my form, with the image 4010737399_df630e8a3a_o.jpg in the photo input. I get sent to the add.php page and the following errors are displayed:

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near '`'. (severity 15) in D:\Hosting\a90\html\sales\add.php on line 25

Warning: mssql_query() [function.mssql-query]: Query failed in D:\Hosting\4a\html\sales\add.php on line 25

Warning: move_uploaded_file(unitimages/4010737399_df630e8a3a_o.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\Hosting\4a\html\sales\add.php on line 28

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php4D71.tmp' to 'unitimages/4010737399_df630e8a3a_o.jpg' in D:\Hosting\45a90\html\sales\add.php on line 28
Sorry, there was a problem uploading your file.

Here is my form page's code where the image is inputted:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
 <form enctype="multipart/form-data" action="add.php" method="POST"> 
 Name: <input type="text" name="title"><br> 
 E-mail: <input type="text" name = "description"><br> 
 Phone: <input type="text" name = "make"><br> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Add"> 
 </form>
</body>
</html>

Here is the full PHP page code for the add.php page:

 <?php 

 //This is the directory where images will be saved 
 $target = "unitimages/"; 
 $target = $target . basename( $_FILES['photo']['name']); 

 //This gets all the other information from the form 
 $name=$_POST['title']; 
 $email=$_POST['description']; 
 $phone=$_POST['make']; 
 $pic=($_FILES['photo']['name']); 

 // Connects to your Database 

$conn = mssql_connect('garce.com','Gdr','Rg1!');
mssql_select_db('Ggler',$conn);
if(! mssql_connect )
{
  die('Could not connect: ' . mssql_get_last_message());
}

 //Writes the information to the database 
 $mmssql_query = ("INSERT INTO `used_trailers1` VALUES ('$name', '$email', '$phone', '$pic')") ; 

 $Test=mssql_query($mmssql_query, $conn);

 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['photo']['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."; 
 } 
 ?> 

Thank you for any help. All help is greatly appreciated.

展开全部

  • 写回答

1条回答 默认 最新

  • dongyo7931 2014-02-24 12:54
    关注

    Seems like you have 2 issues. One is the MSSQL error. The other is a permissions error.

    1) Try removing the backticks around used_trailers1.

    2) Double check that the user that your web server runs as has write permissions in that directory you are trying to move the file too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部