numeric value passing
Posted: Mon Mar 28, 2005 10:53 am
Hi,
I’m trying to have a numeric value passed to a table with a column called Counties_IDFK.
I’m using a select box to pass the value but for some reason I’m not succeeding. I keep getting the error “Column 'TeachTypes' cannot be null” which is what I would expect as this column must have a value in the SQL database.
I’m using the select dropdown box (below too) on another page too and it works fine so I don’t understand why I’m not getting the value passed here.
Any help would be most appreciated. I have posted the full code rather than a snip as I’m not sure where the error might be.
Thanks a mil
Brian
Phenom | Hey look at that, we have
I’m trying to have a numeric value passed to a table with a column called Counties_IDFK.
I’m using a select box to pass the value but for some reason I’m not succeeding. I keep getting the error “Column 'TeachTypes' cannot be null” which is what I would expect as this column must have a value in the SQL database.
I’m using the select dropdown box (below too) on another page too and it works fine so I don’t understand why I’m not getting the value passed here.
Any help would be most appreciated. I have posted the full code rather than a snip as I’m not sure where the error might be.
Thanks a mil
Brian
Code: Select all
<?php
mysql_select_db($database_imtdatabase, $imtdatabase);
$query_rstSearchLocations = "SELECT * FROM locations ORDER BY Counties_IDPK ASC";
$rstSearchLocations = mysql_query($query_rstSearchLocations, $imtdatabase) or die(mysql_error());
$totalRows_rstSearchLocations = mysql_num_rows($rstSearchLocations);
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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO teachers (FirstName, LastName, Address1, Address2, Address3, Phone, Mobile, Email, Website, Counties_IDFK, TeachTypes, AllInstruments, Qualifications, Comments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['FirstName'], "text"),
GetSQLValueString($_POST['LastName'], "text"),
GetSQLValueString($_POST['Address1'], "text"),
GetSQLValueString($_POST['Address2'], "text"),
GetSQLValueString($_POST['Address3'], "text"),
GetSQLValueString($_POST['Phone'], "text"),
GetSQLValueString($_POST['Mobile'], "text"),
GetSQLValueString($_POST['Email'], "text"),
GetSQLValueString($_POST['Website'], "text"),
GetSQLValueString($_POST['Counties_IDPK'], "text"),
GetSQLValueString($_POST['TeachTypes'], "int"),
GetSQLValueString($_POST['AllInstruments'], "text"),
GetSQLValueString($_POST['Qualifications'], "text"),
GetSQLValueString($_POST['Comments'], "text"));
mysql_select_db($database_imtdatabase, $imtdatabase);
$Result1 = mysql_query($insertSQL, $imtdatabase) or die(mysql_error());
$insertGoTo = "insert_update.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Irish Music Teachers</title>
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">FirstName:</td>
<td><input type="text" name="FirstName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">LastName:</td>
<td><input type="text" name="LastName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Address1:</td>
<td><textarea name="Address1" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Address2:</td>
<td><textarea name="Address2" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Address3:</td>
<td><textarea name="Address3" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Phone:</td>
<td><input type="text" name="Phone" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Mobile:</td>
<td><input type="text" name="Mobile" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="Email" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Website:</td>
<td><input type="text" name="Website" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Choose Location:</td>
<td><?PHP echo "<select name='Counties_IDPK' id='Counties_IDPK'>\n";
// this has replaced the a codeing row that usually is entered above by DW
while($dbRow = mysql_fetch_array($rstSearchLocations)){
echo "<option value='"
. $dbRow["Counties_IDPK"]
. "'>"
. $dbRow["Counties_Name"]
."</option>\n";
} echo "</select>\n";
?> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TeachTypes:</td>
<td><input type="text" name="TeachTypes" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">AllInstruments:</td>
<td><input type="text" name="AllInstruments" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Qualifications:</td>
<td><textarea name="Qualifications" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Comments:</td>
<td><textarea name="Comments" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td 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>Code: Select all
tags [/color][/size]