I have a database of schools, I would like to make it so that when you search the database for existing data, it outputs right next the the input box. So without going to a new page. Here's what a have:
<form action=" " method="post">
School's name: <input type="text" name="schoolname"> <br/>
<input type="submit" name="button" value="Search">
</form>
<?php
$school = $_POST['schoolname'];
$conn = mysql_connect("localhost", "root");
mysql_select_db("finalproject");
$sql = "select * from presentations where school like '%$school%'";
$result = mysql_query($sql, $conn) or die(mysql_error());
if ( mysql_num_rows($result) >0)
{
while ($newArray = mysql_fetch_array($result))
{
$school = $newArray['school'];
$date = $newArray['date'];
$place = $newArray['place'];
$time = $newArray['time'];
echo $school . ", " . $place . ", " . $date . ", " . $time . "<br />" ;
}
}
else
{
echo "Record not found";
}
mysql_close($conn);
?>
This is code that I have used previously to link to another page, outputting there. but now I just want to output it on the same page. I did move some code over from the other page which no longer seems to be working. The PHP bit just outputs: "0) { while ($newArray = mysql_fetch_array($result)) { $school = $newArray['school']; $date = $newArray['date']; $place = $newArray['place']; $time = $newArray['time']; echo $school . ", " . $place . ", " . $date . ", " . $time . " " ; } } else { echo "Record not found"; } mysql_close($conn); ?>" onto my page below the input. I'm really new to this, so anyones help would be greatly appreciated. :D
$_POST['schoolname']
isset
before searching the database. – aziz punjani Jan 7 at 18:57