简体   繁体   中英

PHP POST & GET on the Same Page

Im running into Trouble here, im self learning php and trying to sort out POST and GET on the same vieworder.php

for POST i have vieworder.php and for the GET i am using vieworder.php?order_id=550c92216efdb

my Post is working and Sending data to the Database but When i click on vieworder.php?order_id=550c92216efdb its telling giving me Undefined index: for all fields..

Your undefined index error is because when you send a GET request $_REQUEST['pizzaSize'] , and your other $_REQUEST keys aren't set.

Use isset() to determine if they are set or not as your other code does.

Your SQL error is because order_id is a string and needs to be encased in quotes.

$sql = 'SELECT * FROM order WHERE order_id = "' . htmlspecialchars($_GET['order_id']) . '"';

Also you should consider reading up on SQL injection. I could delete your whole database with a dodgy pizzaSize (amoung others) variable.

Try using

if (isset($_POST['your_post_variable_name'])){}

for catch your post and

if (isset($_GET['your_get_variable_name'])){}

for get. In this way you can handle each one separately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM