PHP使用GET方法 [英] PHP uses GET method

查看:139
本文介绍了PHP使用GET方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < form action =addScript.phpmethot =POSTenctype =多部分/格式数据> 
< tr>
< td>产品标题:< / td>< td>< input type =textname =titleid =title/>< / td>
< / tr>
< tr>
< td>产品描述:< / td>< td>< textarea rows =5cols =40name =descriptionid =description>< / textarea> < / TD>
< / tr>
< tr>
< td>价格(USD $):< / td>< td>< input type =textname =priceid =price/>< / td>
< / tr>
< tr>
< td>个人资料图片:< / td>< td>< input type =filename =profilepicid =profilepic/>< / td>
< / tr>
< tr>

< td>其他图片:< / td>< td>
< div id =picturesstyle =border:1px solid black;>< table>
< tr>< td> 1< / td>< td>< input type =fileid =pic1name =pic1/>< / td> TR>
< tr>< td> 2< / td>< td>< input type =fileid =pic2name =pic2/>< / td> TR>
tr< td> 3< td>< td>< input type =fileid =pic3name =pic3/>< / td>< TR>
< / table>
< / div>
< / td>
< / tr>
< tr>
< td>< / td>< td>< input type =submitvalue =Add/>< / td>
< / form>

问题是,即使我使用方法POST,当它调用addScript.php时,使用的方法实际上是GET,我的链接是 www.domain.com/addScript.php?name= ..& description = ... etc。
如果我在php文件中使用 $ name = $ _ REQUEST ['title']; ,我得到这个错误:未定义的索引:title / home / domain /public_html/addScript.php on line 13 。我该如何解决这个问题?



编辑
这是我的PHP没有mysqli_connect();


$ b $

  $ name = $ _ POST ['title']; 
$ description = $ _ POST ['description'];
$ price = $ _ POST ['price'];
$ profilePic = $ _ FILES ['profilepic'] ['name'];
$ path =images /;

//在图片/文件夹中移动图片并获得它们的路径
$ 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;

//在数据库中插入信息
$ sql =INSERT INTO产品(名称,说明,价格,profile_pic,pic1,pic2,pic3)
VALUES
'$名', '$说明', '$价格',$ profilePic, '$ pic1Path', '$ pic2Path', '$ pic3Path');
if(!mysqli_query($ con,$ sql)){
die(ERROR.mysqli_error($ con));
}

我总是收到这个错误

 错误您的SQL语法错误;请检查第3行
$ b

重新编辑:



现在我可以看到回复的确认,但它填充我的error_log这些错误,并在数据库中的列大多是空的。

  [05-Feb-2014 15:01 :12 UTC] PHP注意:未定义的索引:在第13行的/home/domain/public_html/addScript.php中的标题
[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注意:Undefined index:price in /home/domain/public_html/addScript.php on line 15
[05-Feb-2014 15:01:12 UTC] PHP注意:未定义的索引:profilepic in /home/domain/public_html/addScript.php on line 16
[05-Feb-2014 15 :01:12 UTC] PHP注意:未定义索引:pic1在/home/domain/public_html/addScript.php在线20
[05-Feb-2014 15:01:12 UTC] PHP注意:未定义的索引:pic1 in /home/domain/public_html/addScript.php on line 21
[05-Feb-2014 15 PHP的注意:未定义的索引:pic2在/home/domain/public_html/addScript.php在线24
[05-Feb-2014 15:01:12 UTC] PHP公告:未定义索引:图2在/home/domain/public_html/addScript.php 25行
[05-Feb-2014 15:01:12 UTC] PHP注意:未定义索引:pic3在/home/domain/public_html/addScript.php在线28
[05-Feb-2014 15:01:12 UTC] PHP注意:未定义的索引:pic3在/home/domain/public_html/addScript.php上线29

重新编辑

code> var_dump($ _ REQUEST); 在$ name之前的PHP文件中,并得到这个

  array(7){[name] =>字符串(4)aaaa[description] =>字符串(7)aaaaaaa[price] =>字符串(3)555[profilepic] =>字符串(7)cr7.jpg[pic1] =>字符串(9)copac.jpg[pic2] => string(9)close.png[pic3] =>字符串(12)obiectiv.jpg} 1产品增加了

但是DB中的列仍为空。

解决方案

您的表单中有错字。您键入 methot 而不是方法

 < form action =addScript.phpmethot =POSTenctype =multipart / form-data> 

应该是

 < form action =addScript.phpmethod =POSTenctype =multipart / form-data> 

更新
<

 ('$ name','$ description','$价格',$ profilePic','$ pic1Path','$ pic2Path','$ pic3Path'); 
^^^^^
这里

应该是

 ('$ name',' $说明, '$价格', '$ profilePic', '$ pic1Path', '$ pic2Path', '$ pic3Path'); 
^^^^^
这里


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.

解决方案

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

这篇关于PHP使用GET方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆