I'm building a web application that connects to a database which has got a couple of variables stored that's necessary for the site to function properly.
Right now I'm using php to connect and fetch the information but in the end it would be much easier to use a .html file, so I'm planning on using AJAX to fetch the information instead.
I've got this code:
$(function ()
{
$.ajax({
url: 'api.php',
data: {
paramName: $("#partyIDInput").val()
},
method: post,
dataType: 'json',
success: function(data)
{
var id = data[0];
var pID = data[1];
var pLOC = data[2];
var pNAME = data[3];
var pFORMID = data[5];
var pFORMSONG = data[6];
var pFORMARTIST = data[7];
var pFORMNAME = data[8];
$('#partyTitle').append(""+pNAME+"");
}
});
});
Which fetches all the variables via api.php which looks like this:
<?php
$db = new PDO('mysql:host=xxxxx;dbname=xxxxx;charset=utf8', 'xxxxx', 'xxxxx');
$partyInput = $_POST['paramName'];
$stmt = $db->prepare("SELECT * FROM playr_partyID_db WHERE partyID = $partyInput");
$stmt->execute(array($_POST['paramName']));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
But my problem is that I've got a text input on the web page, when a user writes a "partyID" in it and clicks continue I want the script to fetch the information from the row with that ID. Now it's only fetching from the 1st row.
I've never worked with AJAX before so if you've got the time, please explain what's happening too.
Thanks in advance.
Edit:
Here's the input, note that I haven't optimized the page in terms of css yet.
<form style="margin-top:150px;" method="post" action="">
<div class="list-block">
<ul>
<li class="item-content" style="background: #fff;margin-bottom: -26px;">
<div class="item-inner">
<div class="item-input">
<input style="text-align:center;padding:0;" type="text" name="partyID" placeholder="Ange PartyID">
</div>
</div>
</li>
</ul>
</div>
<div class="list-block">
<ul>
<li>
<input type="submit" name="submit" value="Festa på!" class="login_bttn" style=" background: none;color: white;border: 1px solid white;border-radius: 500px;width: auto;margin-left: auto;margin-right: auto;margin-top: 40px;"></input>
</li>
</ul>
<div class="list-block-labe"></div>
</div>
</form>