Hello!
I have PHP and mySQL set up on a server, and everything works fine. I am able to connect to the SQL database successfully, etc. However, I want to set it up so that a user enters their "ID" in an input box. Then, the php script will return the row of data starting with their ID number. I have already written code for this, following a tutorial, and the input box shows up. However, when I click "submit", the box is cleared and nothing happens. I would appreciate any help, as I've spent a long time trying to figure out what's wrong.

search1.php

<html>
<head>
<title>Student Search</title>
<style type="text/css">
table {
background-color: #FCF;
}

th {
width: 150px;
text-align:left;
}
</style>
</head>
<body>
<h1>Student Search</h1>
<form method = "post" action="search1.php">
<input type="hidden" name="submitted" value="true" />
<label>Student ID:
<select name="category">
<option value="ID">ID</option>
</select>
</label>
<label>Search Criteria: <input type="text" name="criteria"/></label>
</form>
<?php

if (isset($_POST['submitted'])) {
//connect to the database
include ('mcon.php');

$category = $_POST['category'];
$criteria= $_POST['criteria'];
$query = "SELECT * FROM student_info WHERE $category = '$criteria'";
$result = mysqli_query($dbcon, $query) or die('Error getting data.');

echo "<table>";
echo "<tr>
<th>ID</th>
<th>Project</th>
<th>Starter Project</th>
<th>Course</th>
<th>KDs Completed in your Course</th>
<th>Projects Completed</th>
<th>Project 1</th>
<th>P1KD1</th>
<th>P1KD2</th>
<th>P1KD3</th>
<th>P1KD4</th>
<th>P1KD5</th>
<th>Project 2</th>
<th>P2KD1</th>
<th>P2KD2</th>
<th>P2KD3</th>
<th>P2KD4</th>
<th>P2KD5</th>
<th>Project 3</th>
<th>P3KD1</th>
<th>P3KD2</th>
<th>P3KD3</th>
<th>P3KD4</th>
<th>P3KD5</th>
<th>Project 4</th>
<th>P4KD1</th>
<th>P4KD2</th>
<th>P4KD3</th>
<th>P4KD4</th>
<th>P4KD5</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['Project'];
echo "</td><td>";
echo $row['Starter Project'];
echo "</td><td>";
echo $row['Course'];
echo "</td><td>";
echo $row['KDs completed in your course'];
echo "</td><td>";
echo $row['Projects Completed'];
echo "</td><td>";
echo $row['Project 1'];
echo "</td><td>";
echo $row['P 1 K D 1'];
echo "</td><td>";
echo $row['P 1 K D 2'];
echo "</td><td>";
echo $row['P 1 K D 3'];
echo "</td><td>";
echo $row['P 1 K D 4'];
echo "</td><td>";
echo $row['P 1 K D 5'];
echo "</td><td>";
echo $row['Project 2'];
echo "</td><td>";
echo $row['P 2 K D 1'];
echo "</td><td>";
echo $row['P 2 K D 2'];
echo "</td><td>";
echo $row['P 2 K D 3'];
echo "</td><td>";
echo $row['P 2 K D 4'];
echo "</td><td>";
echo $row['P 2 K D 5'];
echo "</td><td>";
echo $row['Project 3'];
echo "</td><td>";
echo $row['P 3 K D 1'];
echo "</td><td>";
echo $row['P 3 K D 2'];
echo "</td><td>";
echo $row['P 3 K D 3'];
echo "</td><td>";
echo $row['P 3 K D 4'];
echo "</td><td>";
echo $row['P 3 K D 5'];
echo "</td><td>";
echo $row['Project 4'];
echo "</td><td>";
echo $row['P 4 K D 1'];
echo "</td><td>";
echo $row['P 4 K D 2'];
echo "</td><td>";
echo $row['P 4 K D 3'];
echo "</td><td>";
echo $row['P 4 K D 4'];
echo "</td><td>";
echo $row['P 4 K D 5'];
echo "</td></tr>";
}

echo "</table>";

} //end of main if statement

?>

</body>
</html>

mcon.php (simple connection file)

<?php
DEFINE ('DB_USER','root');
DEFINE ('DB_PSWD','water123');
DEFINE ('DB_HOST','localhost');
DEFINE ('DB_NAME','MathGuide');

$dbcon = msqli_connect(DB_HOST,DB_USER, DB_PSWD,DB_NAME);





?>

I don't see any submit button. How do you submit the form?

You can change the hidden input into submit button. Change this code:

<input type="hidden" name="submitted" value="true" />

into this code:

<input type="submit" name="submitted" value="Submit" />
Member Avatar for diafol

Just a thought. Are the students logged in to your site? Is the project data 'confidential'? If no and yes, what's stopping a student typing in somebody else's id and getting info?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.