Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 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 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...