This is what I am wanting to do with the code. It does not perform properly as I get a 500 error.
- Have user input a first and last name
- Verify that there is a valid input in both of the text boxes
- On button press query database
- If data is returned display header & table
- If no data is returned display a message on screen that no data exists.
I have put together the below syntax, but somewhere syntactically there is an issue, and I can not spot it. Can someone with more experience than I, view this code and help me get it up and running?
<html>
<tbody>
<form method="POST">
Last Name:<input type="text" name="lastname">
First Name:<input type="text" name="firstname">
<input type="submit" name="submit" value="Get Info">
</tbody>
</html>
</form>
<table border="1">
<thead>
<tr>
<th >Second Answer </th>
<th>First Answer </th>
</tr>
</thead>
<tbody>
<?php
if(isset($_POST['submit'])){
$fnameerror = false;
$lastnameerror = false;
if (empty($_POST['firstname'])) {
$fnameerror = true;
}
if (empty($_POST['lastname'])) {
$lastnameerror = true;
}
if ($fnameerror) {
echo "<strong>Please input the first name.</strong><br>";
} else if ($lastnameerror) {
echo "<strong>Please input a last name.</strong><br>";
} else {
$option = array();
$option['driver'] = 'mssql';
$option['host'] = '192.168.X.XXX';
$option['user'] = 'hamin';
$option['password'] = 'ha';
$option['database'] = 'Test';
$option['prefix'] = '';
$db = JDatabase::getInstance( $option );
$query = $db->getQuery(true); } }
?>
<html>
<head>
</head>
<body>
<table border="1">
<thead>
<tr>
<th >Second Answer </th>
<th > First Answer </th>
</tr>
</thead>
</table>
</div>
<div>
<div>
<table border="1" width="960px">
<?php
$query = "Select Top 3 second, first from orderhistory";
$db->setQuery($query);
$query = $db->loadObjectList();
if($query)
{
if ($query->num_rows > 0)
{echo"<table>";
foreach( $query as $res ) {
print "<tr>";
print "<td>" .$res->Second."</td>";
print "<td>" .$res->First."</td>";
print "</tr>";
}
echo"</table>";
}
else {
echo "<h3 align=\"center\">No Data Returned.</h3>";
}
else {
echo "<br> Database error.";
}
?>
</table>
</div>
<br>
</div>
</body>
</html>