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 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化