I am stuck in this issue since long and tried to search for solution but couldn't figure it out. I have input field, where user will type Occation Name that is already exist in Event table, and then I wrote php code so the entire row will be shown for that occationname. below is my code, and I always get the first row of the table (which means it is not doing the checking or WHERE condition). I tried to assign $X value like : $X = gh (gh is occation name that exist in the table) and it works perfectly. It seems that the php is executed on page load, means before user type the input value. (but that does not make any sense as why it shows the first row then?)
NOTE: I used if(issset($_POST['s']) to get if user click on button, but it is not working as the php code is executed before clicking
function GetI()
{
var x = document.getElementById("tt").value;
document.getElementById("tvalue").value = x ;
}
<input type="text" id="tt" value="" class="contactField"/> </br>
<input type="submit" class="pageapp-login-button button button-small button-green button-fullscreen " style="font-size:13px" value="getValue" onclick="GetI()" />
<form method="post" name="addingform1" id="addingform1" action="testing.php" >
<!-- Here in tvalue, I just show this input to make sure the variable is copying the same input that user typed -->
<input type="text" id="tvalue" value="" class="contactField"/>
<input type="submit" name="s" class="pageapp-login-button button button-small button-green button-fullscreen " style="font-size:13px" value="Fordata"/>
<?php header("Content-type: text/html; charset=utf-8");
if(isset($_POST['s']))
$X= $_POST['tvalue'];
include('database/connect-mysql.php');
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
$sqls = "SELECT Date, Address, City, TotalGuest FROM Events WHERE OccationName = '$X'";
echo " <table id='tid'style= 'border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
position:absolute;
top:20%;
right:20%;
'>
<th><div style='overflow: auto; height: 30px; width: 100px;'>Date</th>
<th><div style='overflow: auto; height: 30px; width: 100px;'>Address</th>
<th><div style='overflow: auto; height: 30px; width: 100px;'>City</th>
<th><div style='overflow: auto; height: 30px; width: 100px;'>TotalGuest</th>
</tr>
";
foreach ($dbcon->query($sqls) as $row){
echo "<tr >";
echo "<td>" . $row['Date'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . $row['TotalGuest'] . "</td>";
echo "</tr>";
}
?>
</form>