Hack Forums
[PHP] Revieve GET inputs from admin.php?page=del_order&&ordernumber=1 - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Revieve GET inputs from admin.php?page=del_order&&ordernumber=1 (/showthread.php?tid=5260438)



Revieve GET inputs from admin.php?page=del_order&&ordernumber=1 - Tɦɛ Alex - May 5, 2016

Hey guys,

The other day I asked how I can redirect pages using something like:

admin.php?page=orders

I got my answer, but now I have a new problem. Basically some of my pages rely on GET based data, so how can I do this exact same thing:

admin.php?page=del_order&&ordernumber=1

I believe my syntax is right, but what code should be in admin.php and what code should be in del_order.php

This is the final piece of my puzzle guys, and it'd be great if you could help me out!


* - Kedox - May 5, 2016

if code from admin.php is running code from del_order.php using a include or require then using $_GET on del_order.php will work

e.g

admin.php

PHP Code

<?php 
if ($_GET['page'] == 'del_order') {
    require_once 
'del_order.php';
} 

del_order.php
PHP Code

<?php 
sprintf
('You are deleting order %s from the database', $_GET['ordernumber']); 

if you visit admin.php?page=del_order&ordernumber=1 you will get the response
Code
You are deleting order 1 from the database



* - Tɦɛ Alex - May 5, 2016

(May 5, 2016 01:30 PM)Kedox Wrote:  if code from admin.php is running code from del_order.php using a include or require then using $_GET on del_order.php will work

e.g

admin.php

PHP Code

<?php 
if ($_GET['page'] == 'del_order') {
    require_once 
'del_order.php';
} 

del_order.php
PHP Code

<?php 
sprintf
('You are deleting order %s from the database' . $_GET['ordernumber']); 

if you visit admin.php?page=del_order&ordernumber=1 you will get the response
Code
You are deleting order 1 from the database

You're perfectly right, I thought I'd tried this originally but it didn't work, looks like I must've coded it wrong. Thanks for the help +rep

/Thread


* - Scy7e - May 5, 2016

(May 5, 2016 01:30 PM)Kedox Wrote:  
PHP Code

<?php 
if ($_GET['page'] == 'del_order') {
    require_once 
'del_order.php';
} 

Use strict comparison (===) when comparing strings, == is bad practice.

(May 5, 2016 01:30 PM)Kedox Wrote:  del_order.php
PHP Code

<?php 
sprintf
('You are deleting order %s from the database', $_GET['ordernumber']); 

if you visit admin.php?page=del_order&ordernumber=1 you will get the response
Code
You are deleting order 1 from the database

While this works, this is also bad practice. You should use GET only to access a resource and retrieve data and DELETE (or at least POST) to delete a resource.


* - ๖ۣۜCitizen Z / Napalm - May 6, 2016

(May 5, 2016 01:29 PM)Jackk Wrote:  I got my answer, but now I have a new problem. Basically some of my pages rely on GET based data, so how can I do this exact same thing:

admin.php?page=del_order&&ordernumber=1

Heres an example code for this, modify it too will:
PHP Code

<?php
if(empty($_GET['page']) OR empty($_GET['ordernumber'])){
echo 
"Page Error !";
} else {
$page = $_GET['page'];
$order_num = $_GET['ordernumber'];

if(
$page == "del_order"){
echo 
"Delete Order <br> Options <br> Forms, blablabla";
} elseif(
$page == "add_order") {
echo 
"Add Order <br> Options <br> Forms, blablabla";
}
} 



* - Kenny Schrub™ - May 6, 2016

this is easy you just have to use same method for another parameter


* - Kedox - May 6, 2016

(May 5, 2016 11:13 PM)Scy7e Wrote:  Use strict comparison (===) when comparing strings, == is bad practice.

ok master, didnt know del_order can be read as any other datatype

(May 5, 2016 11:13 PM)Scy7e Wrote:  While this works, this is also bad practice. You should use GET only to access a resource and retrieve data and DELETE (or at least POST) to delete a resource.

It was obviously an example 😶😶
I seriously don't get what kind of moron you think I am


* - DevNet - May 6, 2016

It is stupid to force RESTful stuff through a beginners throat. It's not like you can do DELETE requests natively on all common devices anyway.


* - Scy7e - May 6, 2016

(May 6, 2016 07:53 AM)Kedox Wrote:  ok master, didnt know del_order can be read as any other datatype

While del_order can't, why not stick to using the correct comparisons where they belong? There's no point in complicating it, it's just one extra character so no reason to not use === here. I also doubt OP knew that about string comparisons, so hopefully he learns something new.

(May 6, 2016 07:53 AM)Kedox Wrote:  It was obviously an example 😶😶
I seriously don't get what kind of moron you think I am

You may know that, but OP doesn't. I didn't correct you thinking you were a moron, I said it so that OP (and anyone else reading this thread) wouldn't get used to bad practices thinking there's nothing wrong doing that. But I do think we shouldn't give examples that are clearly idiotic when there's a better way to do them. DELETE might be too extreme in this case, but he should at least do it using POST.

(May 6, 2016 08:04 AM)DevNet Wrote:  It is stupid to force RESTful stuff through a beginners throat. It's not like you can do DELETE requests natively on all common devices anyway.

That's why I said he should at least use POST. Using GET to delete stuff is just a no-no.