As others have mentioned, you can't have PHP directly in the HTML, so you need to escape all those variables in a PHP code block. If this were my code though, I'd consider refactoring a bit, so that I could use JSON encoded parameters, e.g.:
<?php
$rawData = array('id'=>$id, 'first'=>$first, 'last'=>$last, ... );
$hitData = json_encode($rawData);
?>
<button onclick="addHit(<?php echo $hitData ?>)">Checkin</button>
function addHit(inputData)
{
$.ajax({
type: "POST",
url: "checkinuser.php",
data: inputData
success: function(msg) {
alert( "Checked In! " + msg );
}
});
}
In response to your edit, if you want to keep the params the way you have them, I'd modify your while loop:
<?php
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i, "StudentID");
$first=mysql_result($result,$i,"First");
$last=mysql_result($result,$i,"Last");
$date= date("Y.m.d");
?>
<div id='list'>
<div id='id'>
<?php echo $id?>
</div>
<div id='name'>
<?php echo "$first $last" ?>
<button onclick='addHit( <?php echo "$id,$first,$last,$classname,$day,$times,$date" ?> )'
Checkin
</button>
</div>
</div>
<?php
$i++;
}
?>
The goal here is to make it easier to read/write, so separating static code (e.g. HTML) from dynamic code as much as possible can be a good thing. One big advantage is that you don't have to worry about escaping quotes like you do, though a disadvantage is having a fair number of <?php> blocks.
Also note that you're setting id='id' for all these divs, which won't work since they'll all share one id when id's need to be unique on a given page. You probably want to echo $id there too.
Similarly, there's no reason to have echo"</div></div></div></div>"; - move that outside the PHP block and just leave it as HTML.
Finally, in your javascript, you're data parameter is the literal string:
"id=id&first=first&last=last&classname=classname&day=day×=times&date=date"
This won't work as id will literally be 'id', first will be 'first', etc.
You need to either use the method I have above (where you pass the whole parameter), or build up the object to pass as your data param. .ajax() will take objects, so I'd make it an object, and pass that, e.g.:
function addHit(id, first, last, classname, day, times, date)
{
inputData = { id: id, first: first, etc, etc}
$.ajax({
type: "POST",
url: "checkinuser.php",
data: inputData,
success: function(msg){
alert( "Data Saved: " + msg ); //Anything you want
}
});
}