Forum Moderators: coopster

Message Too Old, No Replies

PHP - Collecting the values of checkboxes in Session variable

where is it going wrong

         

Habtom

9:22 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

Please look at the code below and trace where exactly the problem lies.

<?php
if (isset($_POST['cmdproceed'])) {
if (isset($_POST['c1']))
{
$_SESSION['checkvalues'] = $_POST['c1'];
}
else
{
$_SESSION['checkvalues'] = 0 ;
}
if (isset($_POST['c2']))
{
.$_SESSION['checkvalues'] = $_POST['c2'];
}
else
{
.$_SESSION['checkvalues'] = 0 ;
}
if (isset($_POST['c3']))
{
.$_SESSION['checkvalues'] = $_POST['c3'];
}
else
{
.$_SESSION['checkvalues'] = 0 ;
}
if (isset($_POST['c4']))
{
.$_SESSION['checkvalues'] = $_POST['c4'];
}
else
{
.$_SESSION['checkvalues'] = 0 ;
}
if (isset($_POST['c5']))
{
$_SESSION['checkvalues'] = $_POST['c5'];
}
else
{
.$_SESSION['checkvalues'] = 0 ;
}
if (isset($_POST['c6']))
{
$_SESSION['checkvalues'] = $_POST['c6'];
}
else
{
.$_SESSION['checkvalues'] = 0 ;
}
if (isset($_POST['c7']))
{
$_SESSION['checkvalues'] = $_POST['c7'];
}
else
{
.$_SESSION['checkvalues'] = 0 ;
}
if (isset($_POST['c8']))
{
$_SESSION['checkvalues'] = $_POST['c8'];
}
else
{
.$_SESSION['checkvalues'] = 0 ;
}
echo $_SESSION['checkvalues'];
}
?>

Habtom

dreamcatcher

9:47 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Habtom, what exactly is the problem?

Use print_r to debug arrays:

echo print_r($_SESSION);

Habtom

10:19 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. I figured it out now.

I would like to know another thing though. In a number, for example, 9721 - Any function which can help me check if the number 7 exists or not.
something like

if (function(9721) == 7) { do something }

Thanks,
Habtom

dreamcatcher

11:04 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

preg_match should be ok for this:

$number = '9721';

if (preg_match("{7}", $number))
{
//number 7 found
}
else
{
//not found
}

dc

Habtom

3:55 pm on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Dream