How to insert a variable in a database which is calculated by 3 form fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ORB30
    New Member
    • Jul 2010
    • 4

    How to insert a variable in a database which is calculated by 3 form fields

    Hello all

    Im having an issue trying to insert a variable in to a database.
    This variable is the math result of 3 fields of the form, a division multiplied by a number.

    So far is returning always 0 so i thought you might gime me a hand here

    This is the cold below :

    Code:
    // declare variables to be inserted
    $venzini_kinisis_1 = ($_REQUEST['15']/$_REQUEST['8']) * $_REQUEST['1'];
    $venzini_100ara = ($_REQUEST['16']/$_REQUEST['9']) * $_REQUEST['2'];
    $venzini_super_1 = ($_REQUEST['17']/$_REQUEST['10']) * $_REQUEST['3'];
    $venzini_95_1 = ($_REQUEST['18']/$_REQUEST['11']) * $_REQUEST['4'];
    $venzini_95_2 = ($_REQUEST['19']/$_REQUEST['12']) * $_REQUEST['5'];
    $venzini_super_2 = ($_REQUEST['20']/$_REQUEST['13']) * $_REQUEST['6'];
    $venzini_kinisis_2 = ($_REQUEST['21']/$_REQUEST['14']) * $_REQUEST['7'];
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "insert_form")) {
    $insertSQL = sprintf("INSERT INTO kiniseis (polisi_kinisis_1, polisi_100aras, polisi_super_1, polisi_95_1, polisi_95_2, polisi_super_2, polisi_kinisis_2) VALUES (%s, %s, %s, %s, %s, %s, %s)",
    
    GetSQLValueString($_POST['".$venzini_kinisis_1"'], "double"),
    GetSQLValueString($_POST['".$venzini_100ara"'], "double"),
    GetSQLValueString($_POST['".$venzini_super_1"'], "double"),
    GetSQLValueString($_POST['".$venzini_95_1"'], "double"),
    GetSQLValueString($_POST['".$venzini_95_2"'], "double"),
    GetSQLValueString($_POST['".$venzini_super_2"'], "double"),
    GetSQLValueString($_POST['".$venzini_kinisis_2"'], "double"));
    Thanks in advance :)
  • BOMEz
    New Member
    • Dec 2007
    • 40

    #2
    Are you sure that at no point in time one of your variables which is a denominators is a 0? If it is then it could cause you to get 0.

    Try simply echoing all of the variables to actually see what their values are

    Comment

    • ORB30
      New Member
      • Jul 2010
      • 4

      #3
      i use @ to avoid that thing :) so not to receive a notice from php "division by zero" i will echo and get back to see what is happening

      Comment

      Working...