daddyb1 Posted September 29, 2011 Share Posted September 29, 2011 I am new to php. I have been at this for 8 hours and I am not getting anywhere. The objective is to convert the 4-file html/php application into a 1-file php application and generate exactly the same answers and look as the original. I also attached the files. step1.html: <html> <head><title>STEP1</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <form action="step2.php" method="post"> ENTER INPUT1(A or B): <select name="input1"> <option>A</option> <option>B</option> </select> <input type="submit" value="ENTER"/> </form> </div></body></html> step2.php <html> <head><title>STEP2</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <?php $choice=$_POST["input1"]; if($choice=="A") { echo "<form action='step4.php' method='post'>"; echo "<input type='hidden' name='input1' value='5'/>"; } else if($choice=="B") { echo "<form action='step3.php' method='post'>"; echo "<input type='hidden' name='input1' value='1'/>"; } else { echo "<form action='step1.html' method='post'>"; } ?> ENTER INPUT2(1-10) : <input type='text' name='input2' size='3'> <input type="submit" value="ENTER"/> </form> </div></body></html> step3.php: <html> <head><title>STEP3</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <?php $x="1"+$_POST["input1"]; $y="1"+$_POST["input2"]; $z=(int)$x+(int)$y+2; echo "<div class='output'>OUTPUT: "; if($y<=15) { echo "$z.$y.$x";} else { echo "$x.$y.$z";} echo "</div>"; ?> <div class="note">MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="step1.html">RESTART</a> </div></body></html> step4.php: <html> <head><title>STEP4</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <?php $xf="1"+$_POST["input1"]; $xz="2"+$_POST["input2"]; $xaq=(int)$xf; $xax=(int)$xz; if($xaq>$xax) {$xaq=$xaq+33;$xax=$xax+31;} else {$xaq=$xaq+2;$xax=$xax+44;} echo "<div class='output'>OUTPUT: "; echo "$xf.$xaq.$xax.$xz"; echo "</div>"; ?> <div class="note">NOTE: MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="step1.html">RESTART</a> </div></body></html> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/ Share on other sites More sharing options...
AltarofScience Posted September 29, 2011 Share Posted September 29, 2011 I merged the pages, but i do have one question, are you editing the CSS file. Can you show it to me? In order to merge the documents properly I have to know what sorts of layout changes you are making with CSS styling. Did you alter element positions or anything like that? <html> <head><title>STEP1</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <form action="step2.php" method="post"> ENTER INPUT1(A or B): <select name="input1"> <option>A</option> <option>B</option> </select> <input type="submit" value="ENTER"/> </form> </div> <div class="block"> <?php $choice=$_POST["input1"]; if($choice=="A") { echo "<form action='step4.php' method='post'>"; echo "<input type='hidden' name='input1' value='5'/>"; } else if($choice=="B") { echo "<form action='step3.php' method='post'>"; echo "<input type='hidden' name='input1' value='1'/>"; } else { echo "<form action='step1.html' method='post'>"; } ?> ENTER INPUT2(1-10) : <input type='text' name='input2' size='3'> <input type="submit" value="ENTER"/> </form> </div> <div class="block"> <?php $x="1"+$_POST["input1"]; $y="1"+$_POST["input2"]; $z=(int)$x+(int)$y+2; echo "<div class='output'>OUTPUT: "; if($y<=15) { echo "$z.$y.$x";} else { echo "$x.$y.$z";} echo "</div>"; ?> <div class="note">MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="step1.html">RESTART</a> </div> <div class="block"> <?php $xf="1"+$_POST["input1"]; $xz="2"+$_POST["input2"]; $xaq=(int)$xf; $xax=(int)$xz; if($xaq>$xax) {$xaq=$xaq+33;$xax=$xax+31;} else {$xaq=$xaq+2;$xax=$xax+44;} echo "<div class='output'>OUTPUT: "; echo "$xf.$xaq.$xax.$xz"; echo "</div>"; ?> <div class="note">NOTE: MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="step1.html">RESTART</a> </div></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273788 Share on other sites More sharing options...
Pikachu2000 Posted September 29, 2011 Share Posted September 29, 2011 I am new to php. I have been at this for 8 hours and I am not getting anywhere. The objective is to convert the 4-file html/php application into a 1-file php application and generate exactly the same answers and look as the original. You neglected to ask a question. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273796 Share on other sites More sharing options...
AltarofScience Posted September 29, 2011 Share Posted September 29, 2011 I am new to php. I have been at this for 8 hours and I am not getting anywhere. The objective is to convert the 4-file html/php application into a 1-file php application and generate exactly the same answers and look as the original. You neglected to ask a question. But he did state an objective Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273809 Share on other sites More sharing options...
Pikachu2000 Posted September 29, 2011 Share Posted September 29, 2011 Which leads me to believe he wants someone to do his homework for him. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273815 Share on other sites More sharing options...
daddyb1 Posted September 29, 2011 Author Share Posted September 29, 2011 I tried everything and nothing worked. i keep getting a blank page with every attempt and I cannot figure out what I am doing wrong. I want to convert the 4 files to one. What should I do? PLEASE! Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273829 Share on other sites More sharing options...
AltarofScience Posted September 29, 2011 Share Posted September 29, 2011 you want all the html elements to exist on the same page? you need to take the code i edited for you and save it as a file. then open it in the browser. then you need to open the CSS document and edit it so that the elements are displayed properly. alternatively if you want to keep the separate files but have them display together you could use include(''); and have other files that include the specific pages you want. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273831 Share on other sites More sharing options...
daddyb1 Posted September 29, 2011 Author Share Posted September 29, 2011 This is the css. the css will be seperate div.note { font-size: xx-small; color: red ; } div.output { font-size: large; } div.block { width: 500px; border: 2px solid blue ; background: #cccccc; } attachment. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273832 Share on other sites More sharing options...
Pikachu2000 Posted September 29, 2011 Share Posted September 29, 2011 In your php.ini file, find and set these directives as follows, then restart apache. That should shed some light on the 'blank page' issues. error_reporting = -1 display_errors = On Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273834 Share on other sites More sharing options...
daddyb1 Posted September 29, 2011 Author Share Posted September 29, 2011 is there a way to make it look like the original files? I am here at computer for over 12 hours now trying to make it work the way it suppose to. its no longer showing blank. I guess its because I am a novice. The original files are in the zip folder I've attached. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273835 Share on other sites More sharing options...
AltarofScience Posted September 29, 2011 Share Posted September 29, 2011 Create a file called wtf.php in your server public_html or equivalent directory. You will find that the code processes perfectly correctly. It does echo some errors prior to putting inputs in, i would say try isset() so that the code only executes if the variable in isset() is set. although i can't be totally sure that will make errors stop displaying. either way the code displays in firefox as 4 divs with grey and blue styling and what i presume are the correct things because when i input something with the form the output changes. i used an internal style sheet so that i would only have to create one file which was easy to delete from my server folder once i figured out that it was working properly. you can change the name to whatever you want as long as you change the action="" part of the form to the correct new page name. you want the form to go back the the same page as you were on, now that the files arent on separate pages. also obviously you can return to having an external style sheet by change the header to link to it. <html> <head> <style type="text/css"> div.note { font-size: xx-small; color: red ; } div.output { font-size: large; } div.block { width: 500px; border: 2px solid blue ; background: #cccccc; } </style> </head> <body> <div class="block"> <form action="wtf.php" method="post"> ENTER INPUT1(A or B): <select name="input1"> <option>A</option> <option>B</option> </select> <input type="submit" value="ENTER"/> </form> </div> <div class="block"> <?php $choice=$_POST["input1"]; if($choice=="A") { echo "<form action='wtf.php' method='post'>"; echo "<input type='hidden' name='input1' value='5'/>"; } else if($choice=="B") { echo "<form action='wtf.php' method='post'>"; echo "<input type='hidden' name='input1' value='1'/>"; } else { echo "<form action='wtf.php' method='post'>"; } ?> ENTER INPUT2(1-10) : <input type='text' name='input2' size='3'> <input type="submit" value="ENTER"/> </form> </div> <div class="block"> <?php $x="1"+$_POST["input1"]; $y="1"+$_POST["input2"]; $z=(int)$x+(int)$y+2; echo "<div class='output'>OUTPUT: "; if($y<=15) { echo "$z.$y.$x";} else { echo "$x.$y.$z";} echo "</div>"; ?> <div class="note">MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="wtf.html">RESTART</a> </div> <div class="block"> <?php $xf="1"+$_POST["input1"]; $xz="2"+$_POST["input2"]; $xaq=(int)$xf; $xax=(int)$xz; if($xaq>$xax) {$xaq=$xaq+33;$xax=$xax+31;} else {$xaq=$xaq+2;$xax=$xax+44;} echo "<div class='output'>OUTPUT: "; echo "$xf.$xaq.$xax.$xz"; echo "</div>"; ?> <div class="note">NOTE: MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="wtf.html">RESTART</a> </div></body></html> obviously we want you to be able to perform this operation yourself in the future, so i will try to explain what i did. firstly i put all the code in a single set of html tags: <html> <head>\\style sheet</head> <body> \\all of the code </body> </html> then i changed the action tags because otherwise it tried to go to a nonexistent file: step1.php step2.php step3.php step4.php and obviously i don't have those files on my server. of course i also used an internal style sheet with the CSS you provided in the thread, since i don't have the file you linked to externally. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273841 Share on other sites More sharing options...
daddyb1 Posted September 29, 2011 Author Share Posted September 29, 2011 Damn you're good and thank you once more. I have learned a lot tonight. I will follow your concepts and do it the future. Can I display the output only when an option is selected and a number is entered? the original works like that. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273843 Share on other sites More sharing options...
AltarofScience Posted September 29, 2011 Share Posted September 29, 2011 Damn you're good and thank you once more. I have learned a lot tonight. I will follow your concepts and do it the future. Can I display the output only when an option is selected and a number is entered? the original works like that. i don't know. i assume you can if the original did it, provided you change the code a bit. i am actually very new at php, i only learned it to clone a browser game i was banned from(right before one of the staff playing in the server conquered my player group ) and i only started doing the php codes for it about a two weeks ago, and i have really been slacking off aka trying not to fail my college classes, so i'm not very good. i actually didn't read you code that much, although i presume i could figure it out if i had time, so i don't know how your forms and php scripts really work. i am fairly certain i didn't alter any of the actual processing code, just the html tags, so if you have a problem i presume the issue revolves around having all the elements on the same page. sorry i'm not more helpful. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273845 Share on other sites More sharing options...
daddyb1 Posted September 29, 2011 Author Share Posted September 29, 2011 Its okay and the help you have given is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273848 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 I recoded the pages into a single page for you. I havent tested it but the basic functionality is all there.. You should be able to make heads or tails of it and make some changes if need be but if you have any questions, just ask. <?php // Check to see if a step is set, if not set it to step 1 $step = (isset($_GET['step']) ? $_GET['step'] : 1); ?> <html> <head> <title>STEP <?php echo $step; ?>/></title> <link rel="stylesheet" type="text/css" href="steps.css" /> </head> <body> <div class="block"> <?php // If the step is one, show the correct form // if ($step == 1) { echo '<form action="steps.php?step=2" method="post"> ENTER INPUT1(A or B): <select name="input1"> <option value="A">A</option> <option value="B">B</option> </select> <input type="submit" value="ENTER"/> </form>'; } elseif ($step == 2) { // Create the step 2 section of the page // $choice = $_POST["input1"]; if($choice=="A") { echo "<form action='steps.php?step=4' method='post'>"; echo "<input type='hidden' name='input1' value='5'/>"; } elseif($choice=="B") { echo "<form action='steps.php?step=3' method='post'>"; echo "<input type='hidden' name='input1' value='1'/>"; } else { echo "<form action='steps.php' method='post'>"; } echo 'ENTER INPUT2(1-10) : <input type="text" name="input2" size="3" /> <input type="submit" value="ENTER"/> </form>'; } elseif ($step == 3) { // Create the step 3 section of the page // $x="1"+$_POST["input1"]; $y="1"+$_POST["input2"]; $z=(int)$x+(int)$y+2; echo "<div class='output'>OUTPUT: "; if($y<=15) { echo "$z.$y.$x";} else { echo "$x.$y.$z";} echo "</div> <div class=\"note\">MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href=\"steps.php\">RESTART</a>"; } elseif ($step == 4) { // Create the step 4 section of the page // $xf="1"+$_POST["input1"]; $xz="2"+$_POST["input2"]; $xaq=(int)$xf; $xax=(int)$xz; if($xaq>$xax) {$xaq=$xaq+33;$xax=$xax+31;} else {$xaq=$xaq+2;$xax=$xax+44;} echo "<div class='output'>OUTPUT: "; echo "$xf.$xaq.$xax.$xz"; echo "</div> <div class=\"note\">NOTE: MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href=\"steps.php\">RESTART</a>"; } else { echo '<h2>No Step Selected</h2>'; } ?> </div> </body> </html> Edit: Oh I have called the file steps.php, is uses a $_GET variable to read the current step. Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273855 Share on other sites More sharing options...
daddyb1 Posted September 29, 2011 Author Share Posted September 29, 2011 it works perfectly Robert. I would've never be able to do this without the help of you and everyone. THANK YOU 8) 8) :D Quote Link to comment https://forums.phpfreaks.com/topic/248073-merging-file-help/#findComment-1273870 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.