I'm trying to allow a user to check several check boxes and have all
of their selections posted into the same field, rather than using a
multiple selection list. I'm also trying to do this from within
Dreamweaver since [sigh] my knowledge of PHP is only cursory. The
field in the MySQL Database is of the SET data type, with the same
values as those for all the check boxes.

The prevailing wisdom seems to have something to do with setting the
values of the checkboxes as an array, but I'm uncertain as to how to
go about then getting that array up into my database. Below is the
code as it currently stands:

Any thoughts or help would be very much appreciated.

Thanks,

David

*******

<?php require_once('Connections/PoProjDBs.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "") 
{
  $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")) {
  $insertSQL = sprintf("INSERT INTO news (news_title, news_body,
news_date, articlePlace, news_author, review, category) VALUES (%s,
%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString(ereg_replace(' +', ' ',
($_POST['body'])) , "text"),
                       GetSQLValueString($_POST['news_date'], "date"),
                       GetSQLValueString($_POST['select'], "text"),
                       GetSQLValueString($_POST['Author'], "text"),
                       GetSQLValueString(isset($_POST['review']) ?
"true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['category'], "text"));
                                           

  mysql_select_db($database_PoProjDBs, $PoProjDBs);
  $Result1 = mysql_query($insertSQL, $PoProjDBs) or die(mysql_error());

  $insertGoTo = "article_list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<?php
include("fckeditor/fckeditor.php") ;
?>
<!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>Article Insert</title>
<script src="SpryAssets/SpryValidationTextField.js"
type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet"
type="text/css" />
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo
$editFormAction; ?>">
  <table border="1" width="100%">
    <tr>
      <td valign="top">Title</td>
      <td valign="top"><span id="sprytextfield1">
        <input name="title" type="text" id="title" size="50" />
        <span class="textfieldRequiredMsg">A value is
required.</span></span></td>
    </tr>
    <tr>
      <td valign="top">Author</td>
      <td valign="top"><input name="Author" type="text" size="50" /></td>
    </tr>
    <tr>
      <td colspan="2" valign="top"><?php
$oFCKeditor = new FCKeditor('body') ;
$oFCKeditor->BasePath = 'fckeditor/';
$oFCKeditor->Value = 'Enter the news copy here.';
$oFCKeditor->Width  = '80%' ;
$oFCKeditor->Height = '400' ;
$oFCKeditor->ToolbarSet = 'PoProj';
$oFCKeditor->Create() ;
?></td>
    </tr>
    <tr>
      <td colspan="2" valign="top">Where will this article appear?
        <select name="select">
          <option value="interiorOnly" selected="selected">Interior
Pages Only</option>
          <option value="article1">Home Page, Top Article</option>
          <option value="article2">Home Page, Middle Article</option>
          <option value="article3">Home Page, Bottom Article</option>
        </select>
      </td>
    </tr>
    <tr>
      <td colspan="2" valign="top">Check this box if this is a review:
        <input type="checkbox" name="review" value="" /></td>
    </tr>
    <tr>
      <td colspan="2" valign="top">Check all that apply:
        <label>
        <input type="checkbox" name="category[]" value="news" />
        News</label>
        <label>
        <input type="checkbox" name="category[]" value="reviews" />
        Review</label>
        <label>
        <input type="checkbox" name="category[]" value="ppapers" />
        Project Papers</label>
        <label>
        <input type="checkbox" name="category[]" value="interviews" />
        Interview</label>
        <label>
        <input type="checkbox" name="category[]" value="newsletter" />
        Newsletter Articles</label>
        <label>
        <input type="checkbox" name="category[]" value="poems" />
        Poems</label>
        <label>
        <input type="checkbox" name="category[]" value="articles" />
        Articles</label>
        <label>
        <input type="checkbox" name="category[]" value="essays" />
        Essays</label>
      </td>
    </tr>
  </table>
  <?php 
// this splits up the date for the "month/year" field
$date= date("Y-m-d");
?>
  <input type="hidden" name="news_date" value="<?php echo $date ?>">
  <input type="hidden" name="MM_insert" value="form1" />
  <input type="submit" name="submit" id="submit" value="Submit" />
  <input type="reset" name="reset" id="reset" value="Reset" />
</form>
<script type="text/javascript">
<!--
var sprytextfield1 = new
Spry.Widget.ValidationTextField("sprytextfield1");
//-->
</script>
</body>
</html>


Reply via email to