Jump to content

Form Input Data vs. Retrieved from db Data.......


CaseyC1

Recommended Posts

Somebody please pound the answer to this into this hard headed German.

 

I am inputting several variables from a form and then updating a SQL db record with the information. I want to use three of these variables in a calculation. These variables are defined in the db as "Decimal 10,2". Here is the problem:

If I use the variables as they are input (text strings I presume), my calculation does not work (i.e. a multiplication returns the value of 0). However, if I retrieve the values from the db after they have been stored and use the values (i.e. after fetch row $row - $row[my_variable]) in the multiplication everything works.

I would like to use the values after they are input from the form and then store them and my calculation results into the db.  I'm sure the problem is mixed mode multiplication. I have tried to convert the strings to decimal, but no luck.

 

Any answers?

Link to comment
Share on other sites

Ok, as requested:

 

        $catalog_price = $db->mySQLSafe($_POST['catalog_price']);
$myQuery1 = "SELECT markup FROM CubeCart_markup_table WHERE $catalog_price BETWEEN value_from and value_to";
$code = $db->mySQLSafe($_POST['productCode']);
$myQuery2 = "SELECT my_price FROM CubeCart_inventory WHERE productCode = $code";
$myResult1 = mysql_query ($myQuery1);
$myResult2 = mysql_query ($myQuery2);
$row1 = mysql_fetch_array($myResult1, MYSQL_ASSOC);
$row2 = mysql_fetch_array($myResult2, MYSQL_ASSOC);
$my_price = $row2[my_price];
$markup = $row1[markup];
	echo "My price:" .$my_price ."<br>";
	echo "Markup:" .$markup ."<br>";
$retail = $my_price * $markup;
	echo "Retail:" .$retail ."<br>";
//		STORE DATA IN CURRENT RECORD
$record["markup"] = $markup;
$record["price"] = $retail;	

 

The value "my_price" (as input from the html form) is available through

"$my_price = $db->mySQLSafe($_POST['my_price']);"

just as the value "catalog_price" is.  I replaced that statement with the code highlighted in red to retrieve " my_price" from the db.

 

The problem I run into is, when I assign the value of the variable $my_price with $my_price = $db->mySQLSafe($_POST['my_price']);" My multiplication returns a result of 0. If I run with the red code inserted the calculation works.

 

The echo statements are just there to check the variables. There is a <br> at the end of each...that's why the statement looks wrong.

Link to comment
Share on other sites

The output looks from the code as listed above is like this:

 

My price:11.94

Markup:2.05

Retail:24.477

 

When I change the code and use the variable as input through the form, however, the my_price variable looks different and my result is zero. I think the problem might be that there is a format mismatch. In the first example it looks like all three variables are actually numbers. In the example below isn't the My_price a text string? I don't know what php does with a mixed mode expression like this, but I know Fortran IV would throw up......lol

 

My price:'11.94'

Markup:2.05

Retail:0

 

The broader picture.....The script inputs about 23 items through a html form. All of the inputs are through text boxes even though some of the items are defined as decimals in the db. When I use the numbers as they were input through the form, I apparently get a text string. After writing the record to the db and then retrieving the numbers they are in the correct decimal format for the calculation. I would like to be able to convert the strings to a decimal so that I don't have to store the record and then immediately read it back to use the numbers.

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.