Can I use $_POST & $_GET at the same time?

前端 未结 5 751
长发绾君心
长发绾君心 2020-12-20 01:23

I have a following form:

相关标签:
5条回答
  • 2020-12-20 01:33

    Yes you could. $_GET['warehouse'] will be taken from the query string, $_POST variables from submitted POST values.

    0 讨论(0)
  • 2020-12-20 01:33

    Yes, however it should be:

    $field1 = $_POST['field1'];
    $field2 = $_POST['field2'];
    
    $warehouse = $_GET['warehouse'];
    
    $qry = "INSERT INTO table".$warehouse." ( field1, field2 ) VALUES ('".mysql_real_escape_string($field2)."', '".mysql_real_escape_string($field2)."')";
    $result = @mysql_query($qry);
    

    (Fixed syntax)

    0 讨论(0)
  • 2020-12-20 01:35

    I frequently use POST and GET together, so that the PHP side can know whether it was a normal form submission or via AJAX.

    <form action='dest.php'>
    .
    .
    .
    

    vs

    ajaxSubmit( 'dest.php?a=1', ... );
    
    0 讨论(0)
  • 2020-12-20 01:43

    Yes I always do that.

    Also note you should never use mysql_query. Search for php PDO. Not to mention the awful @ for suppressing error

    0 讨论(0)
  • 2020-12-20 01:44

    Yes, this is possible. But you could also use a hidden field:

    <form action="doThis.php">
    <input type="hidden" name="warehouse" value="12" />
    <input name="field1" type="text" />
    <input name="field2" type="text" />
    

    Please be aware that your code is very vulnerable to sql injections!

    0 讨论(0)
提交回复
热议问题