提交后移动图像

时间:2014-02-05 11:28:38

标签: php forms

我有以下代码: HTML:

<html>
 <head>
    <title>Inserare produse in baza de date</title>
    <style>
        table{
            border: 1px solid black;
        }
    </style>
 </head>
 <body>
    <div id="subForm" style="border:1px solid black;text-align:center;">
        <table><form action="addScript.php" methot="POST">
            <tr>
                <td>Produt name : </td><td><input type="text" name="name" id="name" /></td>
            </tr>
            <tr>
                <td>Product description : </td><td><textarea rows="5" cols="40" name="description" id="description"></textarea></td>
            </tr>
            <tr>
                <td>Price (USD $) : </td><td><input type="text" name="price" id="price" /></td>
            </tr>
            <tr>
                <td>Profile Picture : </td><td><input type="file" name="profilepic" id="profilepic" /></td>
            </tr>
            <tr>

                <td>Other pictures : </td><td>
                <div id="pictures" style="border:1px solid black;"><table>
                <tr><td>1</td><td><input type="file" id="pic1" name="pic1" /></td></tr>
                <tr><td>2</td><td><input type="file" id="pic2" name="pic2" /></td></tr>
                <tr><td>3</td><td><input type="file" id="pic3" name="pic3" /></td></tr>
                </table>
            </div>
            </td>
        </tr>
        <tr>
            <td></td><td><input type="submit" value="Add" /></td>
        </form>
    </div>
</html>

PHP

<?php
  //connect to database
    $username="user";
    $password="pass";
    $database="db";
    $con=mysqli_connect("localhost",$username,$password,$database);
  // Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  //get info from form
  $name=$_POST['name'];
  $description=$_POST['description'];
  $price=$_POST['price'];
  $profilePic=$_FILES['profilepic'];
  $path="images/";

  //move picures in image/ folder and get their path
  $pic1=$_FILES['pic1']['name'];
  $pictmp=$_FILES['pic1']['tmp_name'];
  $moveResult=move_uploaded_file($pictmp, $path);

  $pic2=$_FILES['pic2']['name'];
  $pictmp=$_FILES['pic2']['tmp_name'];
  $moveResult=move_uploaded_file($pictmp, $path);

  $pic3=$_FILES['pic3']['name'];
  $pictmp=$_FILES['pic3']['tmp_name'];
  $moveResult=move_uploaded_file($pictmp, $path);

  $pic1Path=$path.$pic1;
  $pic2Path=$path.$pic2;
  $pic3Path=$path.$pic3;

//insert info in database
$sql="INSERT INTO products ( name, description, price, profile_pic, pic1, pic2, pic3)
  VALUES 
  ('$name','$description','$price',$profilePic','$pic1Path','$pic2Path','$pic3Path')";
  if(!mysqli_query($con,$sql)){
    die("ERROR".mysqli_error($con));
  }
  echo "1 product added";
  mysqli_close($con);


?>

我的数据库看起来像这样:

| ID | name | description | price | profile_pic | pic1 | pic2 | pic3|*

* pic来自图片。

问题是:每次我尝试提交表单时,都会收到此错误

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@domain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

我做错了什么?我错过了什么?PHP文件是错误还是什么?

编辑:

我在互联网上发现我已将权限设置为高。新的我把它设置为755我摆脱了错误,但我的脚本仍然无法正常工作,因为最后没有回应。

有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个......

<form action="addScript.php" methot="POST" enctype="multipart/form-data">