0

Hello ,

Im struggling lately to insert a variable to a database table.

The total columns of the table are 52 :confused:

Here is the insert into database script :

<?php require_once('../Connections/my_connection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

// variable creation
$variable_1 = @($row_KINISEIS['kinisis_1c']/$row_KINISEIS['kinisis_1b']) * $row_KINISEIS['kinisis_1a'];
$variable_2 = @($row_KINISEIS['100c']/$row_KINISEIS['100b']) * $row_KINISEIS['100a'];
$variable_3 = @($row_KINISEIS['super_1c']/$row_KINISEIS['kinisis_1b']) * $row_KINISEIS['super_1a'];
$variable_4 = @($row_KINISEIS['95_1c']/$row_KINISEIS['95_1b']) * $row_KINISEIS['95_1a'];
$variable_5 = @($row_KINISEIS['95_2c']/$row_KINISEIS['95_2b']) * $row_KINISEIS['95_2a'];
$variable_6 = @($row_KINISEIS['super_2c']/$row_KINISEIS['super_2b']) * $row_KINISEIS['super_2a'];
$variable_7 = @($row_KINISEIS['kinisis_2c']/$row_KINISEIS['kinisis_2b']) * $row_KINISEIS['kinisis_2a'];

//begin of insert statement
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "insert_form")) {
  $insertSQL = sprintf("INSERT INTO kiniseis (kinisis_1a, `100a`, super_1a, `95_1a`, `95_2a`, super_2a, kinisis_2a, kinisis_1b, `100b`, super_1b, `95_1b`, `95_2b`, super_2b, kinisis_2b, kinisis_1c, `100c`, super_1c, `95_1c`, `95_2c`, super_2c, kinisis_2c, kinisis_1d, `100d`, super_1d, `95_1d`, `95_2d`, super_2d, kinisis_2d, kinisis_1e, `100e`, super_1e, `95_1e`, `95_2e`, super_2e, kinisis_2e, kinisis_a, `100_a`, `95_a`, super_a, kinisis_b, `100_b`, `95_b`, super_b, `date`, fpa, `$variable_1` , `$variable_2` , `$variable_3` , `$variable_4` , `$variable_5` , `$variable_6` , `$variable_7`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
                       GetSQLValueString($_POST['1'], "double"),
                       GetSQLValueString($_POST['2'], "double"),
                       GetSQLValueString($_POST['3'], "double"),
                       GetSQLValueString($_POST['4'], "double"),
                       GetSQLValueString($_POST['5'], "double"),
                       GetSQLValueString($_POST['6'], "double"),
                       GetSQLValueString($_POST['7'], "double"),
                       GetSQLValueString($_POST['8'], "double"),
                       GetSQLValueString($_POST['9'], "double"),
                       GetSQLValueString($_POST['10'], "double"),
                       GetSQLValueString($_POST['11'], "double"),
                       GetSQLValueString($_POST['12'], "double"),
                       GetSQLValueString($_POST['13'], "double"),
                       GetSQLValueString($_POST['14'], "double"),
                       GetSQLValueString($_POST['15'], "double"),
                       GetSQLValueString($_POST['16'], "double"),
                       GetSQLValueString($_POST['17'], "double"),
                       GetSQLValueString($_POST['18'], "double"),
                       GetSQLValueString($_POST['19'], "double"),
                       GetSQLValueString($_POST['20'], "double"),
                       GetSQLValueString($_POST['21'], "double"),
                       GetSQLValueString($_POST['22'], "double"),
                       GetSQLValueString($_POST['23'], "double"),
                       GetSQLValueString($_POST['24'], "double"),
                       GetSQLValueString($_POST['25'], "double"),
                       GetSQLValueString($_POST['26'], "double"),
                       GetSQLValueString($_POST['27'], "double"),
                       GetSQLValueString($_POST['28'], "double"),
                       GetSQLValueString($_POST['29'], "double"),
                       GetSQLValueString($_POST['30'], "double"),
                       GetSQLValueString($_POST['31'], "double"),
                       GetSQLValueString($_POST['32'], "double"),
                       GetSQLValueString($_POST['33'], "double"),
                       GetSQLValueString($_POST['34'], "double"),
                       GetSQLValueString($_POST['35'], "double"),
                       GetSQLValueString($_POST['36'], "double"),
                       GetSQLValueString($_POST['37'], "double"),
                       GetSQLValueString($_POST['38'], "double"),
                       GetSQLValueString($_POST['39'], "double"),
                       GetSQLValueString($_POST['40'], "double"),
                       GetSQLValueString($_POST['41'], "double"),
                       GetSQLValueString($_POST['42'], "double"),
                       GetSQLValueString($_POST['43'], "double"),
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['select_fpa'], "double"),
		       GetSQLValueString($_POST['"$variable_1"'], "double"),
                       GetSQLValueString($_POST['"$variable_2"'], "double"),
                       GetSQLValueString($_POST['"$variable_3"'], "double"),
                       GetSQLValueString($_POST['"$variable_4"'], "double"),
                       GetSQLValueString($_POST['"$variable_5"'], "double"),
                       GetSQLValueString($_POST['"$variable_6"'], "double"),
                       GetSQLValueString($_POST['"$variable_7"'], "double"));

  mysql_select_db($database_my_connection, $my_connection);
  $Result1 = mysql_query($insertSQL, $my_connection) or die(mysql_error());

  $insertGoTo = "../confirmation.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

Can someone find the mistake here , cause its the 1st time that im trying to do this thing :sad:

Thank you very much in advance :)

Edited by freiheit: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by freiheit
0

Line 50 is missing a comma.

To simplify it i give you the below code , but i see only 0 in my database from the values that are supposed to be inserted

// declare variables
$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"));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.