Am having an issue inserting a user selected drop down list value into a MYSQL DB table via a form.
The DDL values which display correctly, are 1 through to 20 and displayed dynamically via the mysql_fetch_assoc function using a basic select * from table query. The MYSQL table field (bet_type_id) type is SMALLINT(3). Whenever I select the bet_type_id from the drop down list and submit the form, the resultant MYSQL table field is updated with zero regardless of what value I have selected.
Any help would be greatly appreciated. I think the issue appears to be with the way I am using the GetSQLValueString($_POST['bet_type_id'], "int") part of the code. When I remove the code and hard-code the value to say 1, the value is successfully inserted into the betslip table bet_type_id field as '1'.
Thanks
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "log_betslip_test")) {
$insertSQL = sprintf("INSERT INTO betslip (bet_date,punter_id,category_id,bet_agency_id,bet_amt,bet_odds,bet_round_id,bet_type_id)
VALUES (%s,%d,%d,%d,%s,%s,%d,%d)",
'now()',
1,
GetSQLValueString($_POST['category_id'], "defined"),
1,
GetSQLValueString($_POST['bet_amount'], "double"),
GetSQLValueString($_POST['odds'], "double"),
2,
GetSQLValueString($_POST['bet_type_id'], "int"));

New Topic/Question
Reply




MultiQuote





|