illuz1on Posted December 23, 2007 Share Posted December 23, 2007 Hey, I have the following piece of code, please could someone tell me if they can see any problems with it? Will echo "table code"; work in the case'1' ? Really need to get this working!! Thanks in advance <body> <?php $thisPage = ( isset($_POST['showpage']) and ctype_digit($_POST['showpage'])? $_POST['showpage'] : '1' ); if ( $thisPage == '7' ) { // This is the last page - show/process results here foreach( $_POST as $name => $value ) { print "$name - $value<br>"; echo "Your quote was generated successfully. It has been sent to Tax Monitor and one of our representatives will contact you with further details."; } else { // Other page - Create form and hidden inputs print '<form method="post" action="'.$_SERVER['php_SELF'].'">'; foreach ( $_POST as $name => $value ) { print '<input type="hidden" name="'.$name.'" value="'.$value.'">'; switch ( $thisPage ) { case '6': print '<input type="hidden" name="showpage" value="5">'; // Put PAGE 4 inputs here // END PAGE 6 break; case '5': print '<input type="hidden" name="showpage" value="5">'; // Put PAGE 4 inputs here // END PAGE 5 break; case '4': print '<input type="hidden" name="showpage" value="5">'; // Put PAGE 4 inputs here // END PAGE 4 break; case '3': print '<input type="hidden" name="showpage" value="4">'; // Put PAGE 3 inputs here // END PAGE 3 break; case '2': print '<input type="hidden" name="showpage" value="3">'; // Put PAGE 2 inputs here // END PAGE 2 break; case '1': default: print '<input type="hidden" name="showpage" value="2">'; // Start PG 1 echo "<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableform"> <tr> <td colspan="3" class="tableheader">Contact Details</td> </tr> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3"><img src="../imgs/spacer.gif" width="57" height="4" /></td> </tr> <tr> <td width="5%" class="formtext"><img src="../imgs/dialup/bullet.gif" width="10" height="10" /></td> <td width="34%" class="formtext">Full Name: </td> <td width="61%"><input type="text" name="textfield" class="textbox"/></td> </tr> <tr> <td class="formtext"><img src="../imgs/dialup/bullet.gif" width="10" height="10" /></td> <td class="formtext">Email Address: </td> <td><input name="textfield2" type="text" class="textbox" /></td> </tr> <tr> <td class="formtext"><img src="../imgs/dialup/bullet.gif" width="10" height="10" /></td> <td class="formtext">Contact Number: </td> <td><input name="textfield3" type="text" class="textbox" /></td> </tr> <tr> <td class="formtext"><img src="../imgs/dialup/bullet.gif" width="10" height="10" /></td> <td class="formtext">Company:</td> <td><input name="textfield4" type="text" class="textbox" /></td> </tr> <tr> <td> </td> <td height="18"><img src="../imgs/spacer.gif" width="57" height="2" /></td> <td> </td> </tr> </table>"; // END PG 1 break; } print '</form>'; } ?> </body> Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 23, 2007 Share Posted December 23, 2007 Case 1 does nothing but fall straight through to Default:, so case 1 will do whatever default does... so, what does it do? As you expect? PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-421776 Share on other sites More sharing options...
illuz1on Posted December 23, 2007 Author Share Posted December 23, 2007 So if i remove the default; will it execute the table code? I intend to put more tables into the other cases, and then at the end print all the input data on case 7... Does the thought behind it work? Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-421831 Share on other sites More sharing options...
illuz1on Posted December 23, 2007 Author Share Posted December 23, 2007 anyone ? ??? Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-421923 Share on other sites More sharing options...
illuz1on Posted December 23, 2007 Author Share Posted December 23, 2007 Ok ive even simplified it, and it still wont work for me when I load the page.. it just shows a blank page as you can see here.. http://taxmon.designrobot.co.za/test.php Im really desperate to get this code working, really would appreciate any advice <body> <?php $thisPage = ( isset($_POST['showpage']) and ctype_digit($_POST['showpage'])? $_POST['showpage'] : '1' ); if ( $thisPage == '7' ) { // This is the last page - show/process results here foreach( $_POST as $name => $value ) { print "$name - $value<br>"; } else { // Other page - Create form and hidden inputs print '<form method="post" action="'.$_SERVER['php_SELF'].'">'; foreach ( $_POST as $name => $value ) { print '<input type="hidden" name="'.$name.'" value="'.$value.'">'; switch ( $thisPage ) { case '6': print '<input type="hidden" name="showpage" value="7">'; // Put PAGE 4 inputs here // END PAGE 6 break; case '5': print '<input type="hidden" name="showpage" value="6">'; // Put PAGE 4 inputs here // END PAGE 5 break; case '4': print '<input type="hidden" name="showpage" value="5">'; // Put PAGE 4 inputs here // END PAGE 4 break; case '3': print '<input type="hidden" name="showpage" value="4">'; // Put PAGE 3 inputs here // END PAGE 3 break; case '2': print '<input type="hidden" name="showpage" value="3">'; // Put PAGE 2 inputs here // END PAGE 2 break; case '1': default: print '<input type="hidden" name="showpage" value="2">'; // Start PG 1 print "hello"; // END PG 1 break; } print '</form>'; } ?> </body> Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-421967 Share on other sites More sharing options...
PFMaBiSmAd Posted December 23, 2007 Share Posted December 23, 2007 Blank php pages are usually the result of fatal parse or fatal runtime errors. I recommend turning on full php error reporting in php.ini or a .htaccess file to get php to help you find out what is happening. Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-422019 Share on other sites More sharing options...
illuz1on Posted February 12, 2008 Author Share Posted February 12, 2008 Ok I get some errors now, Parse error: syntax error, unexpected T_ELSE in /usr/www/users/taxmon/test.php on line 14 Something wrong with the else statement? Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-464709 Share on other sites More sharing options...
aschk Posted February 12, 2008 Share Posted February 12, 2008 Yeah you didn't close your foreach statement properly... Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-464710 Share on other sites More sharing options...
illuz1on Posted February 12, 2008 Author Share Posted February 12, 2008 how would I close it properly? Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-464725 Share on other sites More sharing options...
nethnet Posted February 12, 2008 Share Posted February 12, 2008 Remove the { after both of your foreach loops. Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-464729 Share on other sites More sharing options...
illuz1on Posted February 12, 2008 Author Share Posted February 12, 2008 Thanks for the help, much appreciated, but im still quite new to this and not sure what exactly to do, gave it a try but still same error.. Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-464733 Share on other sites More sharing options...
illuz1on Posted February 12, 2008 Author Share Posted February 12, 2008 I been looking around, and in the PHP manual its the same as I have there? foreach ($arr as $value) { echo "Value: $value<br />\n"; } Really cant figure out where to remove them Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-464760 Share on other sites More sharing options...
nethnet Posted February 13, 2008 Share Posted February 13, 2008 You don't have to remove them, but you can... If there is only one line of code inside the loop the { and } are unnecessary. More than one line and you need them. What you currently have closes the loops, but you are not closing the if/else statement. Try this: <?php $thisPage = ( isset($_POST['showpage']) and ctype_digit($_POST['showpage'])? $_POST['showpage'] : '1' ); if ( $thisPage == '7' ) { // This is the last page - show/process results here foreach( $_POST as $name => $value ) { print "$name - $value<br>"; } } else { // Other page - Create form and hidden inputs print '<form method="post" action="'.$_SERVER['php_SELF'].'">'; foreach ( $_POST as $name => $value ) { print '<input type="hidden" name="'.$name.'" value="'.$value.'">'; } switch ( $thisPage ) { case '6': print '<input type="hidden" name="showpage" value="7">'; // Put PAGE 4 inputs here // END PAGE 6 break; case '5': print '<input type="hidden" name="showpage" value="6">'; // Put PAGE 4 inputs here // END PAGE 5 break; case '4': print '<input type="hidden" name="showpage" value="5">'; // Put PAGE 4 inputs here // END PAGE 4 break; case '3': print '<input type="hidden" name="showpage" value="4">'; // Put PAGE 3 inputs here // END PAGE 3 break; case '2': print '<input type="hidden" name="showpage" value="3">'; // Put PAGE 2 inputs here // END PAGE 2 break; case '1': default: print '<input type="hidden" name="showpage" value="2">'; // Start PG 1 print "hello"; // END PG 1 break; } print '</form>'; } ?> Theo Quote Link to comment https://forums.phpfreaks.com/topic/82930-will-this-piece-of-code-function-alright/#findComment-465530 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.