DO NOT DEAL WITH THIS MEMBER
May 5, 2016 01:29 PM
(This post was last modified: May 5, 2016 01:32 PM by Tɦɛ Alex.)
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!
May 5, 2016 01:30 PM
(This post was last modified: May 5, 2016 01:37 PM by Kedox.)
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
DO NOT DEAL WITH THIS MEMBER
(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
(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.
BTC: 1PQFRwoyRUTCWMC7anLdVxTp4t22MVoos2
(May 5, 2016 01:29 PM)Tɦɛ Alex 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"; } }
DO NOT DEAL WITH THIS MEMBER
this is easy you just have to use same method for another parameter
May 6, 2016 07:53 AM
(This post was last modified: May 6, 2016 07:54 AM by Kedox.)
(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
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.
May 6, 2016 08:54 AM
(This post was last modified: May 6, 2016 08:57 AM by Scy7e.)
(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.
BTC: 1PQFRwoyRUTCWMC7anLdVxTp4t22MVoos2
|