Jan Jan - 2 months ago 4x
Ajax Question

html select function, posting to php and then display with ajax on html

Below you can see my html and php site. What i would like to do is for user to select a month and press Submit button. This choice is then posted to tablea.php via post and this works. Then i would like php function to find all users that with the same month and post their name and number of hours into the table. This table should be then displayed on html site with the help of ajax.

What i am getting at the moment:

I select a month (for example Januar which is 1), press submit and then i am thrown to PHP site where i can see the table with collums "ime" and "stevilo_ur", but the table is empty. Also the table does not display on my index.html but on tabela.php.

Any help would be much apprtiated since i am really new to programming and stuck here all day.

This is my html site: (index.html)

form action="tabela.php" method="post">
Mesec: <select name="meseci">
<option value="o"> </option>
<option value="1">Januar</option>
<option value="2">Februar</option>
<input type='submit' name='Potrdi!'/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$.ajaxSetup({ cache: false });
$(function () {
$('#meseci').change(function () {
var choice = $(this).val();

and this is my php: (tabela.php)

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
echo "Connected successfully";

$SQL = "SELECT ime, stevilo_ur FROM smart_ure WHERE mesec = ' ". $_POST['meseci']." ' ";
$result = mysqli_query($conn, $SQL);
echo "<table border='1'>
while ( $db_v = mysqli_fetch_assoc($result) ) {
echo "<tr>";
echo "<td>" . $db_v['ime'] ."</td>";
echo "<td>" . $db_v['stevilo_ur'] ."</td>";
echo "</table>";


Try this for your php site:

$x = (isset($_POST['meseci']) ? $_POST['meseci'] : null);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

$result = mysqli_query($conn, "SELECT ime, stevilo_ur FROM smart_ure WHERE mesec = '$x ' ");