orateyouth Posted June 14, 2007 Share Posted June 14, 2007 Hi I am brand new at all this only learned html a couple of weeks ago now trying php. I have made a calculator for my website. The site is about carpet fitting and have made the calculator so people can get an estimate before they go to shops and buy carpet. This is the code for the form. <html> <head> <title>Estimator</tltle> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <table style="position:absolute;top:200;left:400"> <tr> <td> <form method="get" action="Test_Calc1.php"> <b>width in feet:</b> <select name="width"> <option>13</option> <option>16.6</option> </select> <br><br> <b>Length:</b><br> <input type="text" name="length"> <br><br> <b>carpet price</b><br> <input type="text" name="price"> <br><br> <input class="button" type="submit" name="sub" value="calculate" /> <br><br> <div class="bottombox">The Price Is:£ <b><?php include('ans.html'); ?></b></div> </td> </tr> </table> </body> </html> and this is the code for the calculator. <?php $length = $_GET['length']; $width = $_GET['width']; $price = $_GET['price']; $ans = $length * $width / 9 * $price; $answ = 'ans.html'; $fh = fopen($answ, 'w'); fwrite($fh, $ans); fclose($fh); echo ('<meta http-equiv="refresh" content="0;url=Test_Calc0.php" />'); ?> Thanx for any help in advance. The calculator works fine but I wonted to know if there are X amount of people using it at the same time would it interfear with eachother and cause trouble for me later on. And if it would has anyone got any suggestions on how to rectify the problem. Quote Link to comment https://forums.phpfreaks.com/topic/55579-caculator-question/ Share on other sites More sharing options...
soycharliente Posted June 14, 2007 Share Posted June 14, 2007 YOu don't need to write the answer to a file. If two people write to the file at the same exact time, I guess they could see the same answer having put in different numbers. Just echo your $ans variable on the page. That way, it will be unique for everyone. You should check for blank too so you don't get divide by 0 errors or something similar. You could use empty(). I would suggest using POST too. When you use GET, I do this too, but people might just type in random crap in the URL to see what happens. <?php $length = $_POST['length']; $width = $_POST['width']; $price = $_POST['price']; $ans = $length * $width / 9 * $price; ?> <html> <head> <title>Estimator</tltle> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <table style="position:absolute;top:200;left:400"> <tr> <td> <form method="post" action="Test_Calc1.php"> width in feet: <select name="width"> <option>13</option> <option>16.6</option> </select> Length: <input type="text" name="length"> Carpet price: <input type="text" name="price"> <input class="button" type="submit" name="sub" value="calculate" /> <div class="bottombox">The Price Is:£ <?php echo $ans; ?></div> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/55579-caculator-question/#findComment-274584 Share on other sites More sharing options...
orateyouth Posted June 14, 2007 Author Share Posted June 14, 2007 Thanx for your help that works great. Guess its easy when you know how. I think I will be visiting this forum alot in the future. All the best and thanx again. Quote Link to comment https://forums.phpfreaks.com/topic/55579-caculator-question/#findComment-274644 Share on other sites More sharing options...
soycharliente Posted June 15, 2007 Share Posted June 15, 2007 No problem always glad to help. Mark this thread SOLVED if you're through. It's at the bottom on the left. Quote Link to comment https://forums.phpfreaks.com/topic/55579-caculator-question/#findComment-275100 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.