Modernvox Posted November 15, 2009 Share Posted November 15, 2009 Hi Guyz, I am looking to put together an instant quote script. Unfortunately, I can do this in C++ no problem, but with PHP I am having some trouble even after spending a few days reading about using forms with PHP. Now I don't expect anyone to sit here and explain the whole process, so I am asking a simplified version: Using the pseudo code below could someone please transform into the proper code? $oneStory= 100, $twoStories= 175, $threeStories= 225; $oneRoom= 25, $twoRooms= 40, $threeRooms= 55; $addRooms= 10; Prompt user for number of stories Prompt user for number of rooms calculate number of rooms value + number of stories value. echo total. I tried to make this as simple as possible just so I may focus on what your doing here. I'm sure using your example I will be able to code what I need. Thank You in Advance.... Link to comment https://forums.phpfreaks.com/topic/181649-need-to-be-guided-in-the-right-direction/ Share on other sites More sharing options...
abazoskib Posted November 15, 2009 Share Posted November 15, 2009 Hi Guyz, I am looking to put together an instant quote script. Unfortunately, I can do this in C++ no problem, but with PHP I am having some trouble even after spending a few days reading about using forms with PHP. Now I don't expect anyone to sit here and explain the whole process, so I am asking a simplified version: Using the pseudo code below could someone please transform into the proper code? $oneStory= 100, $twoStories= 175, $threeStories= 225; $oneRoom= 25, $twoRooms= 40, $threeRooms= 55; $addRooms= 10; Prompt user for number of stories Prompt user for number of rooms calculate number of rooms value + number of stories value. echo total. I tried to make this as simple as possible just so I may focus on what your doing here. I'm sure using your example I will be able to code what I need. Thank You in Advance.... Are you trying to do this via command line php? I am going to guess not since you talked about forms, so you would set up a form with text input spots with name attributes (i.e. <input type="text" name="stories" /><input type="text" name="rooms" />) for stories and rooms, respectively. Then you will need a submit button (i.e. <input type="submit" name="getQuote" />) At the top of your page you should check to see if your submit button was pressed(using either GET or POST array depending on what you use for the form). Assuming you used POST, I would do something like if(isset($_POST['getQuote'])) { //process here and echo total}. That should be enough to start you off. Link to comment https://forums.phpfreaks.com/topic/181649-need-to-be-guided-in-the-right-direction/#findComment-958122 Share on other sites More sharing options...
Modernvox Posted November 15, 2009 Author Share Posted November 15, 2009 Hi Guyz, I am looking to put together an instant quote script. Unfortunately, I can do this in C++ no problem, but with PHP I am having some trouble even after spending a few days reading about using forms with PHP. Now I don't expect anyone to sit here and explain the whole process, so I am asking a simplified version: Using the pseudo code below could someone please transform into the proper code? $oneStory= 100, $twoStories= 175, $threeStories= 225; $oneRoom= 25, $twoRooms= 40, $threeRooms= 55; $addRooms= 10; Prompt user for number of stories Prompt user for number of rooms calculate number of rooms value + number of stories value. echo total. I tried to make this as simple as possible just so I may focus on what your doing here. I'm sure using your example I will be able to code what I need. Thank You in Advance.... Are you trying to do this via command line php? I am going to guess not since you talked about forms, so you would set up a form with text input spots with name attributes (i.e. <input type="text" name="stories" /><input type="text" name="rooms" />) for stories and rooms, respectively. Then you will need a submit button (i.e. <input type="submit" name="getQuote" />) At the top of your page you should check to see if your submit button was pressed(using either GET or POST array depending on what you use for the form). Assuming you used POST, I would do something like if(isset($_POST['getQuote'])) { //process here and echo total}. That should be enough to start you off. Well, I would like to do it in C++ lol, but that's not feasible. What is Command line that you speak of? Is that without a form, because i would love to do it without a form Anyhow, I am having trouble mixing both php with a form that's why I'm hoping someone can use the example above and code it out so I may know what the proper syntax is. Link to comment https://forums.phpfreaks.com/topic/181649-need-to-be-guided-in-the-right-direction/#findComment-958127 Share on other sites More sharing options...
Modernvox Posted November 16, 2009 Author Share Posted November 16, 2009 Is it possible to use Command Line as an interactive webpage. (Can I use it for this quote script?) Will it allow for users input? Link to comment https://forums.phpfreaks.com/topic/181649-need-to-be-guided-in-the-right-direction/#findComment-958188 Share on other sites More sharing options...
abazoskib Posted November 16, 2009 Share Posted November 16, 2009 You could technically use command line tools with shell_exec() but its sub optimal in this situation. if(isset($_POST['submitQuote'])) { $story_array = array(100, 175, 225); $room_array = array(25,40,55); $addRooms= 10; if(isset($_POST['stories']) && $_POST['stories'] > 0) { $stories = trim($_POST['stories']); } else { //no input entered } if(isset($_POST['rooms']) && $_POST['rooms'] > 0) { $rooms = trim($_POST['rooms']); } else { //no input entered } $rooms_value = $rooms*$room_array[$rooms-1]; $stories_value = $stories*$story_array[$stories-1]; $total = $rooms_value+$stories_value; echo $total; } /*Your form below should have a submit button named 'submitQuote' and also elements names 'stories and 'rooms'. Code above is not tested, and includes some error checking */ Link to comment https://forums.phpfreaks.com/topic/181649-need-to-be-guided-in-the-right-direction/#findComment-958629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.