PDA

View Full Version : using isset with both $_POST and $_GET


madshadow
08-14-2006, 06:39 AM
Hello everyone,

I have a document storage system that lets you type in a field, apply a function that produces dynamic pictures, then save your document.

the problem i have is that the viewing page works fine once the form has been submitted with a "preview button" (using isset($_POST['submitted']....but the problem is when you go to the page from another page using viewpage.php?document_id=10 for instance.

i tried using the following conditionals to make it so EITHER the form has been submitted OR the page has been accessed by being passed a GET variable but i'm having errors:


if (isset($_POST['submitted']) or isset($_GET['document_id'])) {

if (isset($_POST['submitted']) || isset($_GET['document_id'])) {

if (isset($_POST['submitted'])) or if (isset($_GET['document_id'])) {



what is the best way to have both a post and get in the same conditional?

Thanks to everyone for reading this and hopefully helping!

kaydara
08-14-2006, 09:24 AM
if ( $_POST["submited"] && $_GET["id"] )
if ( isset($_POST["submited"]) && $_GET["id"] )

as you wish

Kid Charming
08-14-2006, 05:23 PM
What kind of errors? It's early in the morning, but I don't see any reason your first two options wouldn't work.

madshadow
08-14-2006, 06:28 PM
kaydara and Kid,

For a while i was getting errors expecting { and the like...but now the script is just not functioning as it should.

The thing is I want the function to run if it is submitted by post OR by get.....not both.

Kid Charming
08-14-2006, 06:34 PM
Not functioning as it should...meaning what? The block runs with POST, but not GET? GET but not POST? Neither? Is there and ifelse/else part? If so, does it run?

marek_mar
08-14-2006, 07:25 PM
if (isset($_POST['submitted']) xor isset($_GET['document_id'])) {

madshadow
08-15-2006, 04:24 AM
hey guys,

so i have tried all the above conditionals and i get the same result...which is that the script performs properly when submitted (which means showing a series of pictures based on what is in the textarea) but when the page is accessed through GET the picture sequence function doesn't do anything....only the textarea is visible. the entire part in question is contained within the single conditional i'm talking about here.

could it be some other error on my part that i have overlooked?

thank you all for your continued help...it is much appreciated.

Kid Charming
08-15-2006, 04:59 AM
Is the textarea also inside the conditional? Does the image display rely on any other variables that are being passed via the POST?

Mwnciau
08-15-2006, 01:55 PM
if you put the post submitted value to true:

if ($_POST[submitted]){
// has been submitted
}
elseif (is_numeric($_GET[id]) and $_GET[id] > 0){
// is in url
}

madshadow
08-16-2006, 11:50 PM
thanks all for the suggestions. i realized that my code was so messy that i just used two separate scripts since i need it quickly. i appreciate the help and when i have time i'll look at what i actually did wrong.

again thanks for reading my post and making suggestions.