[英]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 我在这里遇到麻烦,我自学了php并尝试在同一vieworder.php上整理POST和GET
for POST i have vieworder.php and for the GET i am using vieworder.php?order_id=550c92216efdb 对于POST,我具有vieworder.php,对于GET,我正在使用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.. 我的帖子正在工作并将数据发送到数据库,但是当我单击vieworder.php?order_id = 550c92216efdb时,它告诉我未定义的索引:所有字段。
Your undefined index error is because when you send a GET
request $_REQUEST['pizzaSize']
, and your other $_REQUEST
keys aren't set. 您未定义的索引错误是因为在发送GET
请求$_REQUEST['pizzaSize']
,未设置其他$_REQUEST
键。
Use isset()
to determine if they are set or not as your other code does. 使用isset()
来确定是否像其他代码一样设置了它们。
Your SQL error is because order_id
is a string and needs to be encased in quotes. 您的SQL错误是因为order_id
是一个字符串,需要用引号引起来。
$sql = 'SELECT * FROM order WHERE order_id = "' . htmlspecialchars($_GET['order_id']) . '"';
Also you should consider reading up on SQL injection. 您还应该考虑阅读SQL注入。 I could delete your whole database with a dodgy pizzaSize
(amoung others) variable. 我可以用一个狡猾的pizzaSize
(在其他变量中)删除整个数据库。
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. 这样,您可以分别处理每个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.