stumped about php

Hey drop us a line about the show. Feel free to ask questions, provide feedback and criticism, or just ramble on about anything your little heart desires.

Moderators: snarkout, Patrick, dann

Post Reply
jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

stumped about php

Post by jelkimantis » Thu Jun 05, 2008 9:02 am

Hey guys,

I'm posting this here because I think it is quite possibly a too low-brow question for php.net...

I have some code, and it looks like this:

Code: Select all

$main = new main();
// echo ($_POST['choice']. " is your choice");
if(isset($_POST['choice'])){
	$main->select_options();
} else  if(empty($_GET['rid']) && !isset($_SESSION[edit])){
	$main->display_options();
}
if(isset($_SESSION['edit'])){
	$main->insert_cards();
}
if(isset($_GET['rid'])){
	$main->display_cards();
}
It gets passed, at one point in time, the variable $_POST['choice'] = 'new'. Which in turn calls a switch statement, which in turn calls this function:

Code: Select all

public function insert_cards(){
	$recipe = new recipe();
		switch ($_SESSION['edit']){
			case "new":
				// $_SESSION['edit']="card";
				$recipe->new_recipe();
				$_SESSION['edit']="card";
				break;
			case "card":
				if ($_FILES["uploaded_file"]){
					$picture= new image_upload();
					$_SESSION['picture']=$picture->process();
					unset($picture);
					if (!$_SESSION['picture']){
						echo("This recipe will have no picutre<br>");
					} else echo("Thank you for uploading a picture of this Recipe.<br>");
				}

Obviously not the end of the function, but it shows the part that I'm having trouble with. When I call the first switch statement, which calls the appropriate function based on what I've selected, it then calls this function which displays a new entry into the recipe database. The unfortunate part is that something I am doing is forcing this code to spit out the new recipe interface twice, but only going to the case "card": after the second time.

Any ideas?

jsl

User avatar
shopRatt
Posts: 107
Joined: Fri Sep 23, 2005 2:20 pm
Location: Canton, Michigan

Re: stumped about php

Post by shopRatt » Thu Jun 05, 2008 9:19 am

If you are talking about 'low-brow', you have come to the right place. :lol:
//brian

User avatar
dann
Site Admin
Posts: 1132
Joined: Mon Apr 26, 2004 10:55 pm
Location: Hampton, Va, USA
Contact:

Re: stumped about php

Post by dann » Thu Jun 05, 2008 9:24 am

so let me get this straight.

You hit the page and nothing is set. You click a button to get a "new" choice so it presents you with the interface. You enter your choice and click a button again and it process the script presenting you with the form to select a new choice and the choice you selected? Is that what you are saying?

Is it carrying the $_POST['choice'] value the second time and tripping the inclusion of said part of the script?

jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Re: stumped about php

Post by jelkimantis » Thu Jun 05, 2008 9:29 am

Nope. To be sure I just added

Code: Select all

<input type="hidden" name="choice" value="">
to what is being echo'ed, I am also going to echo $_POST['choice'] to see if it is being set again, but I don't think it is.

jsl

just echoed out $_POST['choice'] and as true-to-form, $_POST was reset when the page refreshed, so the second time the page was displayed, it did not show $_POST['choice'] as being set.

User avatar
dann
Site Admin
Posts: 1132
Joined: Mon Apr 26, 2004 10:55 pm
Location: Hampton, Va, USA
Contact:

Re: stumped about php

Post by dann » Thu Jun 05, 2008 9:43 am

I am not understanding what is happening here. Could you model what you are seeing and then what it should be doing. Something like:

load page -> click new button -> see form

You said it
it then calls this function which displays a new entry into the recipe database. The unfortunate part is that something I am doing is forcing this code to spit out the new recipe interface twice, but only going to the case "card": after the second time.
Do you me displays a new entry from the database or it puts a new entry into the database? Do you see two new recipe forms on the page from the get go or when you submit the form another appears when it should not or two more appear?

jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Re: stumped about php

Post by jelkimantis » Thu Jun 05, 2008 10:10 am

dann wrote:I am not understanding what is happening here. Could you model what you are seeing and then what it should be doing. Something like:

load page -> click new button -> see form

You said it
it then calls this function which displays a new entry into the recipe database. The unfortunate part is that something I am doing is forcing this code to spit out the new recipe interface twice, but only going to the case "card": after the second time.
Do you me displays a new entry from the database or it puts a new entry into the database? Do you see two new recipe forms on the page from the get go or when you submit the form another appears when it should not or two more appear?
Ok, here's the flowchart:

It *SHOULD* be:
Load Page => select new recipe, press submit => Start new recipe [form] (press submit) => add recipe cards till done [form]

what it IS doing:
Load Page => select new recipe, press submit => start new recipe [form] (press submit) => start new recipe [form] (press submit) => add recipe cards till done.

I did (previously) see two recipe entry forms displayed, but I somehow fixed that (I forget how exactly).

jsl

jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Re: stumped about php

Post by jelkimantis » Thu Jun 05, 2008 10:16 am

I commented out the following code, and it works now?

Code: Select all

		if(!isset($name)){
			$_SESSION['edit']="new";
			die('No name');
		} else if (!isset($gf)){
			$gf="Y";
		} else if(!isset($category)){
			$_SESSION['edit']="new";
			die('No Category');
		} else{
This wonderful pile of code was sitting in the function called to insert a new recipe. (the function which started a new recipe, then allowed you to add cards to that recipe.) I was hoping it would help me to validate the forms, but it just caused this weird error. I can post the complete function, but suffice it to say that the three variables it's looking for were passed to the function, but I guess they would have always been set because they would be set by the calling function... Hmmm.

I think I might just put a little javascript app on the web page to validate that form.

jsl

Post Reply