[SOLVED] Can't get variable to insert into MySQL from PHP
Posted: Tue Jun 22, 2004 11:41 pm
Ok my problem is I am passing a variable from one page to another and it works cause I use a test on line 4, line 3 gets the variable but when I try and input the other 2 variables it's like it either can't see the one I brought over or I am trying to insert it wrond into the record my insert line is between 30 and 40 somewhere. Here is the code.
The message that I keep getting is this:
Column 'file' cannot be null
I am probably missing something simple as it seems most of my mistakes are ones that I should be catching but somehow miss.
Code: Select all
<?php
<?php require_once('Connections/Covuploads.php'); ?>
<?php
$filesname = $_GET['recordID'];
echo "$filesname";
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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO test (test1, test2, file) VALUES (%s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['test1'], "text"),
GetSQLValueString($HTTP_POST_VARS['test2'], "text"),
GetSQLValueString($HTTP_POST_VARS['$filename'], "text"));
mysql_select_db($database_Covuploads, $Covuploads);
$Result1 = mysql_query($insertSQL, $Covuploads) or die(mysql_error());
$insertGoTo = "uploadsuccess.htm";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_Covuploads, $Covuploads);
$query_rs_insert = "SELECT * FROM test";
$rs_insert = mysql_query($query_rs_insert, $Covuploads) or die(mysql_error());
$row_rs_insert = mysql_fetch_assoc($rs_insert);
$totalRows_rs_insert = mysql_num_rows($rs_insert);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p>
<input name="$filename" type="hidden" id="$filename" value="<?php echo $row_rs_insert['file']; ?>">
</p>
<p>Test 1
<input name="test1" type="text" id="test1">
</p>
<p>Test 2
<input name="test2" type="text" id="test2">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input type="hidden" name="MM_insert" value="form1">
</p>
</form>
</body>
</html>
<?php
mysql_free_result($rs_insert);
?>
?>Column 'file' cannot be null
I am probably missing something simple as it seems most of my mistakes are ones that I should be catching but somehow miss.