Link to home
Start Free TrialLog in
Avatar of dereksheahan
dereksheahan

asked on

Problem displaying check-box value

Hi all,
Can't seem to get the update wizard to display the correct values of a check-box. I have the check-boxs defined as Enum (Y,N) in MYSQL and in the Update Wiz I selected the display as check-box submit as check-box Y.N. I've tryed numerous values for the "equal to" field (i.e. Y,N,True) but can't get it working. Any suggestions as to what I might be doing wrong?
Thanks,
D

<?php require_once('../Connections/GSM_mobile.php'); ?>
<?php
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_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE feedback_table SET feed_name=%s, feed_feedback_text=%s, `date`=%s, online=%s, feed_checked=%s WHERE feed_feedback_id=%s",
                       GetSQLValueString($_POST['feed_name'], "text"),
                       GetSQLValueString($_POST['feed_feedback_text'], "text"),
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString(isset($_POST['online']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString(isset($_POST['feed_checked']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['feed_feedback_id'], "int"));

  mysql_select_db($database_GSM_mobile, $GSM_mobile);
  $Result1 = mysql_query($updateSQL, $GSM_mobile) or die(mysql_error());

  $updateGoTo = "adminhome.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsFeedback = "-1";
if (isset($_GET['feed_var'])) {
  $colname_rsFeedback = (get_magic_quotes_gpc()) ? $_GET['feed_var'] : addslashes($_GET['feed_var']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsFeedback = sprintf("SELECT feed_name, feed_feedback_text, `date`, online, feedback_table.feed_feedback_id, feedback_table.feed_checked FROM feedback_table WHERE feedback_table.feed_feedback_id = %s ORDER BY `date` ASC", $colname_rsFeedback);
$rsFeedback = mysql_query($query_rsFeedback, $GSM_mobile) or die(mysql_error());
$row_rsFeedback = mysql_fetch_assoc($rsFeedback);
$totalRows_rsFeedback = mysql_num_rows($rsFeedback);
?><!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
</form>


<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Feed_name:</td>
      <td><input type="text" name="feed_name" value="<?php echo $row_rsFeedback['feed_name']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" valign="top">Feed_feedback_text:</td>
      <td><textarea name="feed_feedback_text" cols="50" rows="5"><?php echo $row_rsFeedback['feed_feedback_text']; ?></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Date:</td>
      <td><input type="text" name="date" value="<?php echo $row_rsFeedback['date']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Online:</td>
      <td><input type="checkbox" name="online" value=""  <?php if (!(strcmp($row_rsFeedback['online'],""))) {echo "@@checked@@";} ?>></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Feed_checked:</td>
      <td><input type="checkbox" name="feed_checked" value=""  <?php if (!(strcmp($row_rsFeedback['feed_checked'],""))) {echo "@@checked@@";} ?>></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Update record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form2">
  <input type="hidden" name="feed_feedback_id" value="<?php echo $row_rsFeedback['feed_feedback_id']; ?>">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($rsFeedback);
?>
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dereksheahan
dereksheahan

ASKER

Sorry Jason,
not sure I understand. Set what exactly in the Wizard to Text?
Got it working! Was the same problem as in the last question! Had to set value equal to 'Y' instead of Y. Great Stuff!
Ah-ha...
Yup, easy when you know how I guess. Just one of those things :)