I want to search with multiple table from by database

This is Search.php

<?php
if(isset($_POST['ActivityId']))
{
require_once('database.php');
$Search=$_POST['Search'];
$query="select * from registration where Flag='A' AND Activity like '%,$Search,%'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}
}
elseif(isset($_POST['EventId'])){
require_once('database.php');
$Search=$_POST['Search'];
$query="select * from participation where EventId ='$Search'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result)){
$LoginId= $row['LoginId'];
echo $LoginId;}
$query="select * from registration where LoginId='$LoginId'";
$result=mysqli_query($dbc,$query) or die('Not Connected to Reg');
while($row=mysqli_fetch_array($result)){
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}}

elseif(isset($_POST['Location']))
{
require_once('database.php');
$Search=$_POST['Search'];
$query="select * from registration where Flag='A' AND Address like '%$Search%'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}
}

elseif(isset($_POST['BloodGroup']))
{
require_once('database.php');
$Search=$_POST['Search'];
$query="select * from registration where Flag='A' AND BloodGroup ='$Search'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
while($row=mysqli_fetch_array($result))
{
echo "<table border='2'><tr><td> Name--".$row['Name']."</td>
<td>Contact Number--".$row['ContactNumber']."</td>
<td>Email--".$row['Email']."</td>
<td>Address--".$row['Address']."</td></tr></table>";
}
}
?>
<html><body><form action='<?php echo $_SERVER['PHP_SELF']?>' method="post">
<input type="text" name="Search"><br>
<input type="submit" name="ActivityId" value="Submit Activity Id"><br>
<input type="submit" name="EventId" value="Submit Event Id"><br>
<input type="submit" name="Location" value="Submit Location"><br>
<input type="submit" name="BloodGroup" value="Submit Blood Group"><br>

</form>
</body></html>

Hi frds…
I have two tables named “registration” and “participation”. Registration table have some columns like “LoginId”, “email”,“contact no.”, “Name” etc.and participation table have 2 column named “LoginId” and “EventId”.
Now if user enters EventId, I want to display the details like email,contact no. etc.
I have a code but it not works properly…
If result have more than one row it only displays the email and contact no. of last one instead of all.
Plzzzzzzzzz help anyone…
???/

to be honest, there is too much code there for me to get my head around when I can’t actually run the code without setting up a test input form first.

however, this could be a good opportunity to hone your debugging skills.

what I would normally do in a situation like this is

  1. start at the top of the script as specified in your form’s action attribute and add
 
echo 'got here'; die();

  1. run your form to check if it gets to your php script

  2. then move the above echo/die down, line by line if you have to, and add appropriate echo statements to display values of variables and then run the form again each time you move the echos.

  3. as part of 3) insert the echos in each part of conditional blocks (IF blocks) to check your code logic is correct

keep doing this until your echos show something is not right. then back track your code to fix the error.

  1. keep repeating 3) and 4) until you get to the end of your script and it works ok.

if you have a debugger, then debugguing will be easier as you can set break points and check values of variables which is essentially what the above steps are doing.

think of debugging as character building.