acpress
asked on
insert into mysql database form with multiple fields that include a checkbox array
I am able to submit all fields into my database with the exception of the art_photos[] checkbox array. All fields enter their correct data but the array inserts the word NULL. Any help would be appreciated as to why the array won't insert my data value. I removed the styles from this code so if you see something regarding Spry, just ignore that part of the code. Here's what I am working with.
<?php virtual('/budgets/Connecti ons/connAd min.php'); ?>
<?php
if (!function_exists("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
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_STR ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE RY_STRING' ]);
}
if ((isset($_POST["MM_insert" ])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO daily_budget (rundate, slug, reporter, budgetInfo, notes, `section`, deadline, art_photos, sidebar, sBudget) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST[' rundate'], "text"),
GetSQLValueString($_POST[' slug'], "text"),
GetSQLValueString($_POST[' reporter'] , "text"),
GetSQLValueString($_POST[' budgetInfo '], "text"),
GetSQLValueString($_POST[' notes'], "text"),
GetSQLValueString($_POST[' section'], "text"),
GetSQLValueString($_POST[' deadline'] , "text"),
GetSQLValueString($_POST[' art_photos '], "text"),
GetSQLValueString($_POST[' sidebar'], "text"),
GetSQLValueString($_POST[' sBudget'], "text"));
mysql_select_db($database_ connAdmin, $connAdmin);
$Result1 = mysql_query($insertSQL, $connAdmin) or die(mysql_error());
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Budget Record</title>
</head>
<body>
<center><h2>Insert Daily Budget </h2></center>
<?php
if (isset($error)) {
echo '<ul>';
foreach($error as $alert) {
echo "<li class='warning'>$alert</li >\n";
}
echo '</ul>';
}
?>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<table align="center" width="60%" border="2" bgcolor="#FFFFFF">
<tr valign="baseline">
<td width="14%" align="right" nowrap="nowrap"><STRONG>Ru ndate:</ST RONG></td>
<td width="86%">
<input type="text" name="rundate" size="30" value="" id="jQueryUICalendar2"/>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><STRONG>Sect ion:</STRO NG></td>
<td>
<select name="section">
<option value=""></option>
<option value="A1">A1</option>
<option value="Pickup All">Pickup All</option>
<option value="Region">Region</opt ion>
<option value="Atlantic">Atlantic< /option>
<option value="Business">Business< /option>
<option value="Features">Features< /option>
<option value="Sports">Sports</opt ion>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Slug :</strong> </td>
<td><span id="sprytextfield2">
<input type="text" name="slug" value="" size="32" />
<span class="textfieldRequiredMs g">REQUIRE D</span></ span><span style="color: #F00; font-weight: bold; font-size: 10px;"></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Budg et Information:</strong></td>
<td><span id="sprytextarea1">
<textarea name="budgetInfo" cols="50" rows="4"></textarea>
<span class="textareaRequiredMsg ">Required .</span></ span><span style="color: #F00; font-weight: bold; font-size: 11px;"></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Note s:</strong ></td>
<td><input type="text" name="notes" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Repo rter:</str ong></td>
<td><span id="sprytextfield3">
<input type="text" name="reporter" value="" size="32" />
<span class="textfieldRequiredMs g">Require d.</span>< /span><spa n style="color: #F00; font-weight: bold; font-size: 10px;"></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Dead line:</str ong></td>
<td><input type="text" name="deadline" size="30" value="Enter date" id="jQueryUICalendar1"/>
> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Artw ork:</stro ng></td>
<td><label>
<input type="checkbox" name="art_photos[]" value="factbox" id="art_photos_0" />
Factbox</label>
<label>
<input type="checkbox" name="art_photos[]" value="graphic" id="art_photos_1" />
Graphic</label>
<label>
<input type="checkbox" name="art_photos[]" value="photo" id="art_photos_2" />
Photo</label>
<label>
<input type="checkbox" name="art_photos[]" value="video" id="art_photos_3" />
Video</label>
<br /></td>
</tr>
<tr>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> <strong>Sidebar:</strong>< /td>
<td valign="baseline"><span id="spryradio2">
<label>
<input type="radio" name="sidebar" value="y" id="sidebar_0" />
Yes</label>
<br />
<label>
<input type="radio" name="sidebar" value="n" id="sidebar_1" />
No</label>
<br />
<span class="radioRequiredMsg">< strong style="font-size: 11px">REQUIRED.</strong></ span></spa n>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Side bar Information:</strong></td>
<td><input type="text" name="sBudget" 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>
<h3><a href="/new_budget/admin/ma nage_budge ts.php"><s trong>View your budget entry, make changes or delete your budget.</strong></a></h3>
</body>
</html>
<?php virtual('/budgets/Connecti
<?php
if (!function_exists("GetSQLV
function GetSQLValueString($theValu
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_rea
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_STR
$editFormAction .= "?" . htmlentities($_SERVER['QUE
}
if ((isset($_POST["MM_insert"
$insertSQL = sprintf("INSERT INTO daily_budget (rundate, slug, reporter, budgetInfo, notes, `section`, deadline, art_photos, sidebar, sBudget) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
GetSQLValueString($_POST['
mysql_select_db($database_
$Result1 = mysql_query($insertSQL, $connAdmin) or die(mysql_error());
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Budget Record</title>
</head>
<body>
<center><h2>Insert Daily Budget </h2></center>
<?php
if (isset($error)) {
echo '<ul>';
foreach($error as $alert) {
echo "<li class='warning'>$alert</li
}
echo '</ul>';
}
?>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<table align="center" width="60%" border="2" bgcolor="#FFFFFF">
<tr valign="baseline">
<td width="14%" align="right" nowrap="nowrap"><STRONG>Ru
<td width="86%">
<input type="text" name="rundate" size="30" value="" id="jQueryUICalendar2"/>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><STRONG>Sect
<td>
<select name="section">
<option value=""></option>
<option value="A1">A1</option>
<option value="Pickup All">Pickup All</option>
<option value="Region">Region</opt
<option value="Atlantic">Atlantic<
<option value="Business">Business<
<option value="Features">Features<
<option value="Sports">Sports</opt
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Slug
<td><span id="sprytextfield2">
<input type="text" name="slug" value="" size="32" />
<span class="textfieldRequiredMs
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Budg
<td><span id="sprytextarea1">
<textarea name="budgetInfo" cols="50" rows="4"></textarea>
<span class="textareaRequiredMsg
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Note
<td><input type="text" name="notes" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Repo
<td><span id="sprytextfield3">
<input type="text" name="reporter" value="" size="32" />
<span class="textfieldRequiredMs
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Dead
<td><input type="text" name="deadline" size="30" value="Enter date" id="jQueryUICalendar1"/>
> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Artw
<td><label>
<input type="checkbox" name="art_photos[]" value="factbox" id="art_photos_0" />
Factbox</label>
<label>
<input type="checkbox" name="art_photos[]" value="graphic" id="art_photos_1" />
Graphic</label>
<label>
<input type="checkbox" name="art_photos[]" value="photo" id="art_photos_2" />
Photo</label>
<label>
<input type="checkbox" name="art_photos[]" value="video" id="art_photos_3" />
Video</label>
<br /></td>
</tr>
<tr>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> <strong>Sidebar:</strong><
<td valign="baseline"><span id="spryradio2">
<label>
<input type="radio" name="sidebar" value="y" id="sidebar_0" />
Yes</label>
<br />
<label>
<input type="radio" name="sidebar" value="n" id="sidebar_1" />
No</label>
<br />
<span class="radioRequiredMsg"><
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Side
<td><input type="text" name="sBudget" 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>
<h3><a href="/new_budget/admin/ma
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.