jamsmyth Posted March 13, 2012 Share Posted March 13, 2012 Hi guys, First off apologies if this is (as I am sure it is) remarkably simple. Current scenario. Page A: I am inserting information on this page into a dbase. Some of this information came from a previous page form which is fine. One element is the result of a calculation carried out on the current page. How do I (is it possible) get the value of that calculation and insert it into the dbase. This all happens on same page. Dazed and Confused. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted March 13, 2012 Share Posted March 13, 2012 nice and easy, assuming you're using PHP: $form1 = $_POST['form1']; $form2 = $_POST['form2']; $form3 = $_POST['form3']; $calcResult = $form2 * $form3; $sql = "INSERT INTO yourTable (fieldName1, fieldName2) VALUES ('$form1', '$form2')"; $result = mysql_query($sql) or die (mysql_error()); you will obviously need to taylor for your own variables but that's the general idea. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 You might want to read up on the session Quote Link to comment Share on other sites More sharing options...
jamsmyth Posted March 13, 2012 Author Share Posted March 13, 2012 Figured I should explain a little more. Here is what I have so far. Page start - <?php $con = mysql_connect("localhost","",""; if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("leads", $con); $sql="INSERT INTO calc_results (date, calc_value, source) VALUES(now(),'$_GET[$format_sum]','$_POST[source]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo ""; ... Then in the body of the same page I have the following <?php $first_number = $first_number.$_POST['payment']."\r\n"; $second_number = $second_number.$_POST['length']."\r\n"; $sum_total = (($first_number / 100) * 20) * ($second_number * 12); // english notation (default) $format_sum = number_format($sum_total, 2); print ($format_sum); ?>! I want to pick up that format sum and insert it right at the start? Is that something that can be done? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted March 13, 2012 Share Posted March 13, 2012 move it to the top of the page? Quote Link to comment Share on other sites More sharing options...
jamsmyth Posted March 13, 2012 Author Share Posted March 13, 2012 Still not picking up the value on the insert. Its picking it up in the body fine but just inserting a blank into the dbase??? <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("leads", $con); $first_number = $first_number.$_POST['payment']."\r\n"; $second_number = $second_number.$_POST['length']."\r\n"; $sum_total = (($first_number / 100) * 20) * ($second_number * 12); // english notation (default) $format_sum = number_format($sum_total, 2); $sql="INSERT INTO calc_results (date, calc_value, source) VALUES(now(),'$_GET[$format_sum]','$_POST[source]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo ""; Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 Why are you using $_GET[$format_sum]? That won't work. You'll need to just use $format_sum I think. Also, you're developing without error_reporting turned on. That's a bad idea, you'll never see your errors. Either turn it on in php.ini or put this at the top of every script you're working on: error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
jamsmyth Posted March 13, 2012 Author Share Posted March 13, 2012 Thanks guys. That got me there. Job Done. Only started using PHP on Friday so def learning as I go (told you I was a Newbie)! Thanks again. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 $_GET is an array of all the variables passed to your page in the URL. Quote Link to comment 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.