ok i have a form that a logged in user files out and then the form data is inserted in a mysql table. works flawlessly. I want be able to when the user submits the form their username is grabbed from
$_SESSION['MM_Username']
and inserted in table with the other data
This is the error that i get | Column 'MM_Username' cannot be null
Here is the Script i am using:
[CODE]<?php require_once('../../Connections/NFacts.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']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO products (department_code, item_code, `description`, keywords, allergy_statement, useable_slices, sodium_compliance, region_availability, order_lead_time, gluten_free, ingredients, link, MM_Username) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['department_code'], "text"),
GetSQLValueString($_POST['item_code'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['keywords'], "text"),
GetSQLValueString($_POST['allergy_statement'], "text"),
GetSQLValueString($_POST['useable_slices'], "text"),
GetSQLValueString($_POST['sodium_compliance'], "text"),
GetSQLValueString($_POST['region_availability'], "text"),
GetSQLValueString($_POST['order_lead_time'], "text"),
GetSQLValueString($_POST['gluten_free'], "text"),
GetSQLValueString($_POST['ingredients'], "text"),
GetSQLValueString($_POST['link'], "text"),
GetSQLValueString($_POST['MM_Username'], "text"));
$to = "someone@mysite.com";
$subject = "New Item Added To Database, Needs Action.";
$message = $_POST['item_code']. " This item was added today into N Factsdatabase, Needs your attention.";
$headers = "From: system@mysite.com";
mail($to, $subject, $message, $headers) ;
mysql_select_db($database_NFacts, $NFacts);
$Result1 = mysql_query($insertSQL, $NFacts) or die(mysql_error());
$insertGoTo = "request-submitted.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
[/code]
Form Located on same page that user fills out
<h4 align="center">Enter Item Specifications: (All fields are required)</h4>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form2" id="form2">
<div align="left">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Item Code (Sku 1 ):</td>
<td><input name="item_code" type="text" id="item_code" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Department Code( 99-999 format):</td>
<td><input name="department_code" type="text" id="department_code" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap="nowrap">Description:</td>
<td><textarea name="description" cols="32" rows="5" id="description"></textarea></td>
</tr>
<tr valign="baseline">
<td height="87" align="right" valign="middle" nowrap="nowrap">Search Keywords:</td>
<td><textarea name="keywords" cols="32" rows="5" readonly="readonly" id="keywords">New Item Please Update</textarea></td>
</tr>
<tr valign="baseline">
<td height="87" align="right" valign="middle" nowrap="nowrap">Ingredients: </td>
<td><label for="ingredients"></label>
<textarea name="ingredients" id="ingredients" cols="32" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap="nowrap">Allergy Statement:</td>
<td><label for="allergy_statement"></label>
<input name="allergy_statement" type="text" id="allergy_statement" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Useable Slices:</td>
<td><input name="useable_slices" type="text" id="useable_slices" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sodium Compliance:</td>
<td><input name="sodium_compliance" type="text" id="sodium_compliance" value="No" size="32" />
YES/NO</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Region Availability:</td>
<td><input name="region_availability" type="text" id="region_availability" value="Buffalo, Rochester, Syracuse" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Gluten Free:</td>
<td><input name="gluten_free" type="text" id="gluten_free" value="No" size="32" />
YES/NO</td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap="nowrap">Prodouct Details Link:</td>
<td><textarea name="link" cols="32" rows="5" readonly="readonly" id="link">Attention New Entry Please Update
<br />
Item Number 99-999
<br />
Description
<br />
<a href="products/#-#.php">View Details For This Item</a></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input name="submit" type="submit" id="submit" onclick="MM_validateForm('item_code','','R','department_code','','R','allergy_statement','','R','useable_slices','','R','sodium_compliance','','R','region_availability','','R','gluten_free','','R','description','','R','keywords','','R','ingredients','','R','link','','R');return document.MM_returnValue" value= "Add Item" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form2" />
<input type="hidden" name="FA" value="SendMail" />
</div>
</form>
<p> </p>
</div>
</div>