Jump to content

Need to be guided in the right direction


Modernvox

Recommended Posts

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....

 

 

 

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.

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.

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 */

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.