Welcome to WebmasterWorld Guest from 54.145.166.96

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Printing checkpoint variables ?!

   
6:07 pm on Apr 17, 2009 (gmt 0)

5+ Year Member



The array is being passed. sizeof($employee) always showing the correct number of boxes passed. But it's not printing. I've looked at tons of tutorials, but none of them quite get me there.


$view_current_employees_sql = "SELECT * FROM com_employee WHERE date_left_employment IS NULL order by first_name";

$view_current_employees_return = mysql_query($view_current_employees_sql);
while($row=mysql_fetch_array($view_current_employees_return))
{
$employee_id = $row[0];
$first_name = $row[1];
$last_name = $row[2];
$pay_scale = $row[3];
$percentage = $row[4];
$date_of_hire = $row[5];

?>
<tr>
<td><input type="checkbox" name="employee[]" value="<?php $employee_id ?>">
</td>
<td><?php echo $first_name?>
</td>
<td><?php echo $last_name?></td>
<td><?php echo $pay_scale?></td>
<td><?php if($percentage == NULL)
echo "n/a";
else
echo $percentage;
?>
</td>
<td><?php if($date_of_hire == NULL)
echo "unknown";
else
echo "$date_of_hire";
?>
</td>
</tr>
if(isset($_POST['employee']))
{
echo "it's set<br/>"; /// WORKS
$employee = $_POST['employee'];
echo "$employee[0]"; ///DOESN'T WORK! :(
}

6:34 pm on Apr 17, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



$employee = $_POST['employee'];
echo "$employee[0]"; ///DOESN'T WORK! :(

What happens if you do this?
echo "$employee";

6:39 pm on Apr 17, 2009 (gmt 0)

5+ Year Member



"Array"
7:12 pm on Apr 17, 2009 (gmt 0)

5+ Year Member



The array is being passed, but I can't seem to be able to print the damned thing. :)
8:34 pm on Apr 17, 2009 (gmt 0)

5+ Year Member



I always go back and try the simplest first:

$view_current_employees_sql = "SELECT * FROM com_employee WHERE date_left_employment IS NULL order by first_name LIMIT 1";

$view_current_employees_return = mysql_query($view_current_employees_sql);
while($row=mysql_fetch_array($view_current_employees_return))
{
print_r($row);

}

See if what that looks like and if your getting what you want / expect from your db query.

William.

1:15 am on Apr 18, 2009 (gmt 0)

5+ Year Member



You can try this:

echo '<pre>'.htmlentities(var_export($employee, true)).'</pre>';

or what i usually do when debugging:

echo '<pre>'.htmlentities(var_export($_REQUEST, true)).'</pre>';

That'll give you a clue about what's exactly being passed into your script. But anyways, i suspect the problem is here:

... value="<?php $employee_id ?>"

I think it should be:

... value="<?php [b]echo[/b] $employee_id[b];[/b] ?>"

Take a look at the generated page's source to see if your <checkbox> is formed properly.

2:16 pm on Apr 18, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



echo "$employee"; --> "Array"

Okay how about var_dump($employee")?

The reason I asked is I was speculating that it might be a scalar string, but if it says "array" then that's what it is. But if it's empty, var_dump will tell you so.

3:44 pm on Apr 18, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



(oops)
var_dump($employee);

(no quote)

11:13 pm on Apr 18, 2009 (gmt 0)

5+ Year Member



for one checkbox checked:
array(1) { [0]=> string(0) "" }

For two checkboxes:
array(2) { [0]=> string(0) "" [1]=> string(0) "" }

etc...

3:14 pm on Apr 19, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Bingo! At least, I think . . . see idfer's last comment.

array(2) { [0]=> string(0) "" [1]=> string(0) "" }

The empty strings tell you there's no value in the checkbox. So when you print "$employee[0]" it actually IS printing $employee[0]. It's just a blank string.

<input type="checkbox" name="employee[]" value="<?php $employee_id ?> <--- Note missing closing " quote

I don't **think** it's from the missing last quote - it might be - but more importantly, make sure you're actually getting a value from $employee_id.

8:13 pm on Apr 19, 2009 (gmt 0)

5+ Year Member



Not quite bingo. There is a value, and it's being properly set. I just checked it out.
2:51 am on Apr 20, 2009 (gmt 0)

5+ Year Member



You're missing the "echo" in that statement, the part i bolded in my other post. You can spot problems like this easily if you do a "view source" of the page in your browser.
5:37 am on Apr 20, 2009 (gmt 0)

5+ Year Member



I did the echo thing but it didn't work. I did find out the problem, or at least a workaround: I took out the $employee_id and put in $row[0] instead and it worked!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month