homepage Welcome to WebmasterWorld Guest from 54.204.90.135
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Printing checkpoint variables ?!
zulubanshee




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

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! :(
}


 

rocknbil




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

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

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

zulubanshee




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

"Array"

zulubanshee




msg:3894826
 7:12 pm on Apr 17, 2009 (gmt 0)

The array is being passed, but I can't seem to be able to print the damned thing. :)

wsmeyer




msg:3894871
 8:34 pm on Apr 17, 2009 (gmt 0)

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.

idfer




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

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.

rocknbil




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

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.

rocknbil




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

(oops)
var_dump($employee);

(no quote)

zulubanshee




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

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

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

etc...

rocknbil




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

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.

zulubanshee




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

Not quite bingo. There is a value, and it's being properly set. I just checked it out.

idfer




msg:3895861
 2:51 am on Apr 20, 2009 (gmt 0)

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.

zulubanshee




msg:3895914
 5:37 am on Apr 20, 2009 (gmt 0)

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved