Hi Guys,
I am new to PHP/MYSQL. I am working on a web database project to record class attendance.
I have found this script which I have manipulated, however, I am not sure why it does not display the data. It may be something simple, I have checked over table names, field names, variable names to see that they match the database. It displays the textboxes with the php code rather than the data and all other fields display no data.
Can you help?
I will be focusing on Prepared Statements for SQL injections later.
<?php
$host="xxx"; // Host name
$username="xxx"; // Mysql username
$password="xxx"; // Mysql password
$db_name="xxx"; // Database name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM attendance";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<html>
<head>
<title>Registers</title>
</head>
<body>
<?php include 'Navigation.php';?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<table border="0" cellspacing="1" cellpadding="0" style="width: 1461px; height: 105px">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Last Name</strong></td>
<td align="center"><strong>First Name</strong></td>
<td align="center"><strong>Form</strong></td>
<td align="center"><strong>Year Group </strong></td>
<td align="center"><strong>Date</strong></td>
<td align="center"><strong>Attendance</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $Student_id[]=$rows['Student_id']; ?><? echo $rows['Student_id']; ?></td>
<td align="center"><? $firstname[]=$rows['firstname']; ?><? echo $rows['firstname']; ?></td>
<td align="center"><? $lastname[]=$rows['lastname']; ?><? echo $rows['lastname']; ?></td>
<td align="center"><? $Form_Group[]=$rows['Form_Group']; ?><? echo $rows['Form_Group']; ?></td>
<td align="center"><? $Year_Group[]=$rows['Year_Group']; ?><? echo $rows['Year_Group']; ?></td>
<td align="center"><? $Att_Date[]=$rows['Att_Date']; ?><? echo $rows['Att_Date']; ?></td>
<td align="center"><input name="Presence[]" type="text" id="Presence" value="<? echo $rows['Presence']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="7" align="center"><input type="submit" name="Submit" value="Submit Register"></td>
</tr>
</table>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE attendance SET Presence='$Presence[$i]' WHERE Student_id='$Student_id[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:Registers.php");
}
mysql_close();
?>