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