• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

who's any good at PHP?

jongyoo

Member
I'm running into some problems when I'm trying to do a simple checkbox deal on php. I was wondering if you guys knew anything I didn't. Take a look at this.


test1.php:

<html>
<body>
<form name=myForm action="test2.php" method="post">
Enter random text
<br>
<li><input type="text" name="test"></li>
<br>
Check me or not:
<INPUT type="checkbox" name="testcheck" value="1"><BR>
<input type="submit" value="Submit">
</form>
</body>
</html>


test2.php:

<html>
<body>
<?
$check = $_POST['testcheck'];
if($check) {
print ('box is checked');
} else{
print ('box is NOT checked');
}
?>
</body>
</html>

But for reason when my box is unchecked my broswer is displaying:

'Notice: Undefined index: testcheck in C:\Program Files\Apache Group\Apache2\htdocs\test2.php on line 5
box is NOT checked'

I don't know how to get rid of this freaking 'Notice'.

When the box is checked then it says:

'box is checked'

which is ok. Anyone have any ideas?
 
its an option in your php.ini, change
error_reporting
variable to
error_reporting = E_ALL & ~E_NOTICE

That will show all errors except for notices (which are like warnings)



 
PM a member here named notfred. He is a very good perl/cgi guy. He might know about php as well.
 
Try:

<?
$check = $_POST['testcheck'];
if($check != null) {
print ('box is checked');
} else{
print ('box is NOT checked');
}
?>
 
Originally posted by: pcthuglife
Try:

<?
$check = $_POST['testcheck'];
if($check != null) {
print ('box is checked');
} else{
print ('box is NOT checked');
}
?>


or use the isnull() function, e.g. if(!isnull($check))
 
Originally posted by: wkinney
Originally posted by: pcthuglife
Try:

<?
$check = $_POST['testcheck'];
if($check != null) {
print ('box is checked');
} else{
print ('box is NOT checked');
}
?>


or use the isnull() function, e.g. if(!isnull($check))

Or, for that matter, (!empty($check))
 
Or, perhaps,

try {

$check = $_POST['testcheck'];

} catch (Exception $e) {
echo 'box is not checked';
$check = false;
}

 
If it's saying there's a problem with the index, then it's in the line "$check = $_POST['testcheck']; "
So, try testing $_POST['testcheck'] directly.
 
Back
Top