Jump to content

JulianHarford

Members
  • Posts

    3
  • Joined

  • Last visited

JulianHarford's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It's starting to make a bit of sense, but it hasn't clicked yet. Like you said, I'll get it eventually. I'll just keep reading and practicing with classes till I nail it down. Thanks again for your help, exeTrix! Much appreciated!
  2. Thanks for explaining, exeTrix! You're right -- I do need to ask myself questions like the ones you mentioned in your post. I've read up a bit on classes/functions, but still trying to get it all in my head. I am slightly confused about the calculateBhp() in your code. From what I understand, the car class defines the attributes of the car. Then you proceed to create "Honda" and "Ford" with that class. So why are you re-creating calculateBhp() those two classes? Wouldn't the logic be the same regardless? Or maybe they need different names? Just trying to absorb classes and functions since I'm quite sure I'll be using both a lot. Thanks for pointing out the form display error, by the way.
  3. Hi all, I've been learning PHP since the beginning of this year. I am self-taught -- I have not received any formal training in programming. I understand some of the basics, but I felt I could do more than just a "Hello World" right now. Anyway, I decided to create a fake app to help improve my PHP knowledge. It's quite simple. Users visit a page that asks them for a choice, then leads them to a form. Ultimately, I'd end up storing the info they provide in a database. I haven't jumped on the database part yet, because I'd like someone experienced to take a look at what I have so far and offer any helpful tips. Currently I have three files in the /cars/ directory: index.html, cars.php, form.php. I figured I'd need one to ask what the customer wants, another that would show a generic form, and the last containing specific forms which would show up based on the choice selected. index.html: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Select car</title> </head> <body> <form action="cars.php" method="POST"> Select the required car(s):<br /> <input type="radio" name="car" value="ford" />Ford <br /> <input type="radio" name="car" value="honda" />Honda <br /> <input type="radio" name="car" value="both" />Both <br /> <input type="submit" name="submit" value="Continue" /> <br /> </form> </body> </html> cars.php: <?php include('form.php'); // Generic form in HEREDOC $cars = <<<FORM Color: <select name="color"> <option value="black">Black</option> <option value="blue">Blue</option> <option value="red">Red</option> <option value="green">Green</option> <option value="yellow">Yellow</option> <option value="pink">Pink</option> <option value="orange">Orange</option> <option value="white">White</option> </select> <br /> Insurance Company: <input type="text" name="insurance" size="20" /> <br /> Insurance Phone No.: <input type="text" name="insurancephone" size="20" /> <br /> No. of drivers: <input type="text" name="drivers" size="5" /> <br /> Lease duration (in hours): <input type="text" name="lease" size="5" maxlength="2" /> <br /> Comments:<br /> <textarea name="comments" rows="3" cols="40"></textarea> FORM; // Check to see if an option was selected before hitting Submit if (isset($_REQUEST['submit'])) { $car = $_REQUEST['car']; // If customer wants both cars if ($car == 'both') { echo 'Your cars will be added under the same list.<br />'; echo $formFord; echo $formHonda; } else if ($car == 'honda') { echo 'Ford choice:<input type="text" name="choiceFord" size=10" /><br />'; echo $formFord; } else { echo 'Honda choice:<input type="text" name="choiceHonda" size=10" /><br />'; echo $formHonda; } echo $cars; } else { echo 'Please go back and choose an option.'; } ?> form.php: <?php $formFord = <<<FORD Cylinders: <select name="cylinder"> <option value="four">4 cylinder</option> <option value="six">6 cylinder</option> <option value="eight">8 cylinder</option> <option value="teh">10 cylinder</option> <option value="twelve">12 cylinder</option> </select> <br /> FORD; $formHonda = <<<HONDA Looking to save? <input type="radio" name="power" value="yes" />Yes <input type="radio" name="power" value="no" />No <br /> Features:<br /> <input type="radio" name="feature" value="all" />All<br /> <input type="radio" name="feature" value="standard" />Standard<br /> <input type="radio" name="feature" value="other" />Custom:<br /> <input type="checkbox" name="custom" value="airbag" />Air bags <input type="checkbox" name="custom" value="remote" />Remote lock <input type="checkbox" name="custom" value="sunroof" />Sunroof<br /> <input type="checkbox" name="custom" value="navi" />Navigation system <input type="checkbox" name="custom" value="bluetooth" />Bluetooth <input type="checkbox" name="custom" value="xmradio" />XM Radio<br /> <input type="checkbox" name="custom" value="foglight" />Foglights HONDA; ?> That is what I have so far, and it currently does what I want it to do. But as you've already noticed, it's not very well-thought out (at least I don't feel like it is). I'm sure there are better ways to accomplish what I put above. Just need some constructive criticism before I keep going any further. On that note, if you feel like I should keep going before I can receive any criticism, I won't mind. Thanks in advance for any help!
×
×
  • 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.