Page 2 of 2

Posted: Fri Jun 01, 2007 8:23 pm
by fullfocus
Hi,

I'm back. I'm finally starting to create my form and table. Before I program everything, I'm running some test data. I was able to successfully set the check to 1 and maintain the choices selected.

But, first, when I run the script for the first time, the first thing that displays on the screen is my message "No Good". Then, the form appears. Once, I make my selections, then the script run fine.

I'm not understanding why the "No Good" is appearing. There is probably something wrong with the syntax but I can't quite see it.

Can you take a look? Thanks for the help.

This is how the screen appears when the script is first called.

No good.

[]Abuse
[]Aggression
[]Allegations of Abuse/Neglect


This is my script.

Code: Select all

<?php
require_once ('mysql_connect.php');

if (isset($_POST['submitted'])) {

  //validate form data  

if (isset($_POST['beh_abuse'])) {
   $_SESSION['beh_abuse'] = 1;
   } else {
   $_SESSION['beh_abuse'] = 0;
  }

if (isset($_POST['beh_aggr'])) {
   $_SESSION['beh_aggr'] = 1;
   } else {
   $_SESSION['beh_aggr'] = 0;
  }

if (isset($_POST['beh_alleg'])) {
   $_SESSION['beh_alleg'] = 1;
   } else {
   $_SESSION['beh_alleg'] = 0;
  }

echo "$_SESSION[beh_abuse]<br>";
echo "$_SESSION[beh_aggr]<br>";
echo "$_SESSION[beh_alleg]<br>";

}
else { 
    echo 'No good.';
} 

?>

<form action="behavior_form_test.php" method="post">
<table>
<tr><td valign="top">
<?php
      if(isset($_SESSION['beh_abuse']) && $_SESSION['beh_abuse'] == '1')
       echo '<input type="checkbox" name="beh_abuse" id="beh_abuse" value="abuse" checked> Abuse&nbsp;';
       else
       echo '<input type="checkbox" name="beh_abuse" id="beh_abuse" value="abuse">Abuse&nbsp;';
?>
</td></tr>

<tr><td valign="top">
<?php
      if(isset($_SESSION['beh_aggr']) && $_SESSION['beh_aggr'] == '1')
       echo '<input type="checkbox" name="beh_aggr" value="beh_aggr" checked> Agression&nbsp;';
       else
       echo '<input type="checkbox" name="beh_aggr" value="beh_aggr">Aggression&nbsp;';
?>
</td></tr>
<tr><td valign="top">
<?php
      if(isset($_SESSION['beh_alleg']) && $_SESSION['beh_alleg'] == '1')
       echo '<input type="checkbox" name="beh_alleg" value="beh_alleg" checked> Abuse&nbsp;';
       else
       echo '<input type="checkbox" name="beh_alleg" value="beh_alleg">Allegations of Abuse/Neglect&nbsp;';
?>
</td></tr>

</table>
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" class="btn" >
<input type="hidden" name="submitted" value="TRUE" />
</form>

Posted: Fri Jun 01, 2007 8:35 pm
by superdezign
Maybe try if(!empty($_POST)) instead of checking for the hidden field.

Posted: Fri Jun 01, 2007 8:46 pm
by fullfocus
I tried. Same result.

Posted: Fri Jun 01, 2007 9:00 pm
by John Cartwright
firstly, your missing a session_start() at the top of your script, secondly try debugging the values you are expecting

Code: Select all

echo '<pre>';
print_r($_POST);
print_r($_SESSION);
echo '</pre>';

Posted: Fri Jun 01, 2007 9:21 pm
by fullfocus
Yes, the missing session_start() caused the problem.

Thanks for seeing it.