PHP uses GET method [closed]

2019-08-23 02:39发布

I have this form :

<form action="addScript.php" methot="POST" enctype="multipart/form-data">
            <tr>
                <td>Produt title : </td><td><input type="text" name="title" id="title" /></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>

The problem is that even if I use method POST, when it calls addScript.php, the method used is actually GET and my link is www.domain.com/addScript.php?name=..&description=... etc. And if I use $name=$_REQUEST['title']; in the php file , I get this error :Undefined index: title in /home/domain/public_html/addScript.php on line 13.How can I solution this?

EDIT This is my PHP without the mysqli_connect();

$name=$_POST['title'];
  $description=$_POST['description'];
  $price=$_POST['price'];
  $profilePic=$_FILES['profilepic']['name'];
  $path="images/";

  //move picures in images/ 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));
  }

And I always get this error

ERROR You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'images/','images/','images/')' at line 3

Re-EDIT :

Now I can see the confirmation echoed, but it fills my error_log with these errors and the columns in the database are mostly empty .

[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: title in /home/domain/public_html/addScript.php on line 13
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: description in /home/domain/public_html/addScript.php on line 14
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: price in /home/domain/public_html/addScript.php on line 15
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: profilepic in /home/domain/public_html/addScript.php on line 16
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: pic1 in /home/domain/public_html/addScript.php on line 20
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: pic1 in /home/domain/public_html/addScript.php on line 21
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: pic2 in /home/domain/public_html/addScript.php on line 24
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: pic2 in /home/domain/public_html/addScript.php on line 25
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: pic3 in /home/domain/public_html/addScript.php on line 28
[05-Feb-2014 15:01:12 UTC] PHP Notice:  Undefined index: pic3 in /home/domain/public_html/addScript.php on line 29

Re-Re-EDIT

I added var_dump($_REQUEST); in the PHP file before the $name and got this

array(7) { ["name"]=> string(4) "aaaa" ["description"]=> string(7) "aaaaaaa" ["price"]=> string(3) "555" ["profilepic"]=> string(7) "cr7.jpg" ["pic1"]=> string(9) "copac.jpg" ["pic2"]=> string(9) "close.png" ["pic3"]=> string(12) "obiectiv.jpg" } 1 product added

But still columns in DB are empty.

标签: php post get
2条回答
对你真心纯属浪费
2楼-- · 2019-08-23 03:26

Please check spelling of "method"

查看更多
疯言疯语
3楼-- · 2019-08-23 03:27

You have a typo in your form. You typed methot instead of method:

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

should be

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

update

You're missing a quote in your SQL query:

('$name','$description','$price',$profilePic','$pic1Path','$pic2Path','$pic3Path')";
                                ^^^^^
                                 HERE  

should be

('$name','$description','$price','$profilePic','$pic1Path','$pic2Path','$pic3Path')";
                                ^^^^^
                                 HERE
查看更多
登录 后发表回答