hello -
i'm inserting into varchar through php/html form but the data is posting in the database as 0 or null.
thanks in advacance for your help.
here is all the code:
i left out the include connections.php
i also moved around the result and query that are commented out trying to see where the isue could be its not that it wont post its posting the wrong data.
i.e. i put 20001 as the zip code it will post 0 and not the 20001
i'm inserting into varchar through php/html form but the data is posting in the database as 0 or null.
thanks in advacance for your help.
here is all the code:
Code:
<?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']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
mysql_select_db($database_enumTest, $enumTest);
$insertSQL = sprintf("INSERT INTO users (users_id, users_name, states_id) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['users_id'], "int"),
GetSQLValueString($_POST['users_name'], "text"),
GetSQLValueString($_POST['states_id'], "int"));
//$Result1 = mysql_query($insertSQL, $enumTest) or die(mysql_error());
// mysql_select_db($database_enumTest, $enumTest);
$insertSQL1 = sprintf("INSERT INTO users_zip (users_id, users_zip_id, users_zip) VALUES (last_insert_id(), null, %s)",
GetSQLValueString($_POST['users_id'], "int"),
GetSQLValueString($_POST['users_zip_id'], "int"),
GetSQLValueString($_POST['users_zip'], "text"));
$Result1 = mysql_query($insertSQL, $enumTest) or die(mysql_error());
}
mysql_select_db($database_userstatesTest, $userstatesTest);
$query_Recordset1 = "SELECT * FROM states";
$Recordset1 = mysql_query($query_Recordset1, $userstatesTest) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Users_id:</td>
<td><input name="users_id" type="text" value="null" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Users_name:</td>
<td><input type="text" name="users_name" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">States_id:</td>
<td><select name="states_id">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['states_id']?>"><?php echo $row_Recordset1['states_name']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">zip code</td>
<td><input type="text" name"users_zip" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
i also moved around the result and query that are commented out trying to see where the isue could be its not that it wont post its posting the wrong data.
i.e. i put 20001 as the zip code it will post 0 and not the 20001
Comment