I checked a multiples threads on the same kind of errors in stackoverflow but I could not find an answer to my query so I am posting this question.
I am using jquery Ajax to pass a variable to a PHP and get the results back but I get the below error
Notice: Undefined variable: captain in C:\fpl\checkCaptain.php on line 22 null
Below are the jQuery and PHP script that I am using.
jQuery AJAX:
$('#outPlayer').change(function(){
$.ajax({
type: "GET",
url: "checkCaptain.php",
data: 'q='+$('#OutPlayer').val(),
success: function(msg){
if(msg == 1)
{ $('#test').html(msg); }
else
{ $('#test').html(msg); }
}
PHP Page:
include_once("includes/mySqlConnect.php");
$query = sprintf("SELECT MAX(gameweek) AS gameweek FROM gameweek");
$sql = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($sql))
{
$gameweek = $row['gameweek'];
}
$outPlayer = $_GET['q'];
$query1 = sprintf("SELECT captain FROM gameweek WHERE gameweek = '%s' AND player = '%s'", $gameweek, $outPlayer);
$sql1 = mysql_query($query1) or die(mysql_error());
while($row1 = mysql_fetch_array($sql1))
{
$captain = $row1['captain'];
}
echo $captain;
I would really appreciate a quick help here. Thanks in advance!! Apologies if there are silly mistakes. I am new to Ajax and PHP :)