I'm try to write a program where a user enters info into a form and upon hitting 'submit' queries the database and then displays the information.
Here's my code for the page the form is on:
//At the very top of the page:
<?php
session_start();
?>
//<body>:
<p>Please enter your student ID# below and hit Submit. </p>
<form id="form1" name="form1" method="post" action="checkstudentattendanceck.php">
<table width="200" border="1">
<tr>
<td><strong>Student ID#:</strong></td>
<td><label>
<input type="text" name="user_id" id="user_id" />
</label></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<label>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</label>
</div></td>
</tr>
</table>
<p> </p>
</form>
<a href="logout.php"> Logout </a>
And here's the code for the page that checks the form upon submission:
//At the very top of the page:
<?php
session_start();
include "include/z_db.php";
?>
//<body>:
<table>
<tr><th>User ID#</th><th> First Name</th><th>Last Name</th><th> Number Attended</th><th> Number Still Needed</th></tr>
<?php
mysqli_select_db($db, 'osumusic_new');
$result = mysqli_query($db, 'SELECT * FROM recitalattenddance WHERE user_id = '$user_id');
while ($row = mysqli_fetch_object($result)) {
printf(
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td<td>%s</td></tr>',
htmlspecialchars($row->user_id),
htmlspecialchars($row->firstname),
htmlspecialchars($row->lastname),
htmlspecialchars($row->number_attended),
htmlspecialchars($row->number_needed)
);
}
mysqli_close($db);
} else {
echo '<tr><td colspan = "4">Connection Failed.
</td></tr>';
}
?>
</table>
When I test this out I get this error message:
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\osumusic\checkstudentattendanceck.php on line 166
Here's what's on line 166:
$result = mysqli_query($db, 'SELECT * FROM recitalattenddance WHERE user_id = '$user_id');
I've tried re-writing this several times and I'm obviously still missing something. Any suggestions?