Jump to content

Newbie (Sorry) Can this be done?


jamsmyth

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 "";

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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