PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 5th, 2005, 04:02 PM
Faylaricia Faylaricia is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Houston, TX
Posts: 12 Faylaricia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool Switches

Okay, my second Newbie question and I do hope one day my questions will become more intelligent... I am still fighting with the PHP book and the author now gives:

<?php
// Debug info Display
function debugDisplay(){
?>
<PRE>
$_POST
<?php
print_r($_POST);
?>
$_GET
<?php
print_r($_GET);
?>
</PRE>
<?php
}
// Switch on search/add wizard step
switch( $_GET['step']){
// #################
// Search/Add form
// #################
case "1":
$type = explode(":",$_POST['type']);
if ($_POST['Submit']=="Add"){
require($_POST['Submit'].$type[0].'.php');
} else {
if ( $_POST['type'] == "Movie:Movie" &&
$_POST['MovieType'] == ""){
header("Location:form4.php");
}
?>
<h1>Search Results</h1>
<p>You are looking for a "<?php echo $type[1]?>" named "<?php echo $_POST['Name']?>"</p>
<?php
}
if ($_POST['Debug'] == "on"){
debugDisplay();
}
break;
// #################
// Add Summary
// #################
case "2":
$type = explode(":",$_POST['type']);
?>
<h1>New <?php echo $type[1]?> : <?php echo $_POST['Name']?></h1>
<?php
switch( $type[0] ){
case "Movie":
?>
<p>Released in <?php echo $_POST['MovieYear']?></p>
<p><?php echo nl2br(stripslashes($_POST['Desc']))?></p>
<?php
break;
default:
?>
<h2>Quick Bio</h2>
<p><?php echo nl2br(stripslashes($_POST['Bio']))?></p>
<?php
break;
}
break;
// ###############
// Starting form
// ###############
default:
require('startform.php');
break;
}
?>




When I put that in my PHP Expert editor (hm, expert, maybe there is the problem? lol) and display it in IE, then it throws be an error message above the table, showing "Notice: Undefined index: step in c:\program files\easyphp1-7\www\form4.php on line 19"
When I display it directly in PHP Expert editor, it shows up fine. Why would IE do that?

Also, the author writes "each step in the building of data is guided by the $_GET['step'] index value. It holds the information passed on by the ?step=1 part of the URL. If the page is called without the URL parameter being set, logically enough, it evaluates the 'switch' condition and finds that it doesn't match any of the specific cases.

Now, I understand the switch condition is : Then how come that
default:
require('startform.php');
break;

would not work in IE? Any ideas???

Thanks. Learning a bit every day.

Reply With Quote
  #2  
Old January 6th, 2005, 10:13 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
In the future, put [php] tags around your PHP code... this way the forum will make your code colourized and it will be prettier for us to read.
Note: You can still edit your post now... but I'd recommend re-pasting your code so the forum doesn't delete your indentation.

Which line is line 19?

Your book sure doesn't make things easy... this code looks much more complicated then I believe it should be... what is the code suppposed to be teaching you? [which chapter of the book is it under?]... and, if you don't mind me asking, which book is it? (and author)

Reply With Quote
  #3  
Old January 6th, 2005, 02:33 PM
Faylaricia Faylaricia is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Houston, TX
Posts: 12 Faylaricia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP Code:
<?php
// Debug info Display
function debugDisplay(){
?>
<PRE>
$_POST
<?php
print_r
($_POST);
?>
$_GET
<?php
print_r
($_GET);
?>
</PRE>
<?php
}
// Switch on search/add wizard step
switch( $_GET['step']){
// #################
// Search/Add form
// #################
case "1":
$type explode(":",$_POST['type']);
if (
$_POST['Submit']=="Add"){
require(
$_POST['Submit'].$type[0].'.php');
} else {
if ( 
$_POST['type'] == "Movie:Movie" &&
$_POST['MovieType'] == ""){
header("Location:form4.php");
}
?>
<h1>Search Results</h1>
<p>You are looking for a "<?php echo $type[1]?>" named "<?php echo $_POST['Name']?>"</p>
<?php
}
if (
$_POST['Debug'] == "on"){
debugDisplay();
}
break;
// #################
// Add Summary
// #################
case "2":
$type explode(":",$_POST['type']);
?>
<h1>New <?php echo $type[1]?> : <?php echo $_POST['Name']?></h1>
<?php
switch( $type[0] ){
case 
"Movie":
?>
<p>Released in <?php echo $_POST['MovieYear']?></p>
<p><?php echo nl2br(stripslashes($_POST['Desc']))?></p>
<?php
break;
default:
?>
<h2>Quick Bio</h2>
<p><?php echo nl2br(stripslashes($_POST['Bio']))?></p>
<?php
break;
}
break;
// ###############
// Starting form
// ###############
default:
require(
'startform.php');
break;
}
?>


Line 19 is
switch( $_GET['step']){

"Beginning PHP, Apache, MySQHL Web Development" by Michael K. Glass, Yann Le Scourarnec, Elizabeth Naramore

This is at the end of Chapter 5 "Forms" and the section is "Using them All". This is what he said at the beginning of this section: Now that you know most of the form elements, let's create a skeleton for the application. The system will add new items or search for existing ones. As we have no database interfacing so far, this form will just display the information typed in. So, this is the "Skeleton Script" for some app. Througout the book, he has us create a website accessing MySQL for movies, reviews, etc.

Thanks for any help!

Reply With Quote
  #4  
Old January 7th, 2005, 07:54 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
This is probably due to how error reporting is setup on your system.

Basically the script on line 19 the script is referring to $_GET['step'] , but i'm willing to guess step doesnt exist, the author is hoping that it will fall through to the default action but instead it is displaying the notice (btw this php giving the error, not IE).
I wouldn't expect a notice to cause the script to fail, it should display then continue.

Try one of the following steps:

PHP Code:
switch( $_GET['step']){ 

becomes
PHP Code:
 $step = isSet( $_GET['step'] ) ? $_GET['step'] : 0;
switch( 
$step){

(
this sets $step $_get['step'] if $_get['step'exists, else sets it to 0.

or try calling the script with form4.php?step=0.
__________________
http://www.phptutorials.cjb.net. go on, give it a click!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Switches


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT