Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

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

I have a following form:

<form action="doThis.php?warehouse=12" method="post">
  <input name="field1" type="text" />
  <input name="field2" type="text" />
</form>

And doThis.php:

$field1 = mysql_real_escape_string($_POST['field1'], $mysql);
$field2 = mysql_real_escape_string($_POST['field2'], $mysql);

$warehouse = $_GET['warehouse'];
if ( !someTableNameValidation($warehouse) ) {
    someErrorHandling();
}
$qry = "INSERT INTO table".$warehouse." ( field1, field2 ) VALUES( '$field2', '$field2') ";
$result = @mysql_query($qry, $mysql);

As you can see, I'm using $_POST to get data from the form, and $_GET to get variable $warehouse which is used to indicate table number.

Can I use both $_POST & $_GET at the same time? Is this kind of usage correct?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...