dongli7236 2014-02-24 20: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 20: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.

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

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算