Define $id to external function in PHP [duplicate]












1
















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers




I am trying to list players into a page, the page already uses a sql query, so i have put this query in a function (below) which sitting in the functions.php, in another file teampage.php I have called the function <?php echo listGoalkeepersForTeam(); ?> , but it is throwing a Notice: Undefined variable: id in C:xampp***functions.php on line 77



how to get function to read the teampage.php?id=1 and display the information accordingly.



function listGoalkeepersForTeam() {

$dbServername = "****";
$dbUserrname = "****";
$dbPassword = "****";
$dbName = "****";

$sql = "select player.fname as fname, player.sname as sname, player.position as position, player.profile_img as profile_img from player_team
join player on player_team.player_id = player.player_id
join team on player_team.team_id = team.team_id
where team.team_id = '$id'
AND player.position = 'Goalkeeper'";


$conn = mysqli_connect($dbServername, $dbUserrname, $dbPassword, $dbName);
$query = mysqli_query($conn, $sql);

if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($query))
{ ?>

<img class="rounded-circle img-fluid d-block mx-auto mr-4" src="img/db_img/players/child.png" alt="<?php echo ($row['fname']. " " .$row['sname']) ?>">
<h3><?php echo ($row['fname']. " " .$row['sname']) ?><br>
<small><?php echo ($row['position']) ?></small>
</h3>


<?php $no++;
}

}









share|improve this question















marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 21:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    We can't see line numbers. What is line 77?

    – Dharman
    Nov 20 '18 at 21:47






  • 1





    It isn't defined and you have a variable scope issue.

    – Funk Forty Niner
    Nov 20 '18 at 21:47






  • 1





    Pass $id as a parameter to the function.

    – Alex Howansky
    Nov 20 '18 at 21:47






  • 1





    @Dharman That edit of yours was unnecessary and modified code also; we can't do that. I rolled it back to Phil's revision.

    – Funk Forty Niner
    Nov 20 '18 at 21:54








  • 1





    You're open to an sql injection here btw. You really should use a prepared statement.

    – Funk Forty Niner
    Nov 20 '18 at 22:03
















1
















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers




I am trying to list players into a page, the page already uses a sql query, so i have put this query in a function (below) which sitting in the functions.php, in another file teampage.php I have called the function <?php echo listGoalkeepersForTeam(); ?> , but it is throwing a Notice: Undefined variable: id in C:xampp***functions.php on line 77



how to get function to read the teampage.php?id=1 and display the information accordingly.



function listGoalkeepersForTeam() {

$dbServername = "****";
$dbUserrname = "****";
$dbPassword = "****";
$dbName = "****";

$sql = "select player.fname as fname, player.sname as sname, player.position as position, player.profile_img as profile_img from player_team
join player on player_team.player_id = player.player_id
join team on player_team.team_id = team.team_id
where team.team_id = '$id'
AND player.position = 'Goalkeeper'";


$conn = mysqli_connect($dbServername, $dbUserrname, $dbPassword, $dbName);
$query = mysqli_query($conn, $sql);

if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($query))
{ ?>

<img class="rounded-circle img-fluid d-block mx-auto mr-4" src="img/db_img/players/child.png" alt="<?php echo ($row['fname']. " " .$row['sname']) ?>">
<h3><?php echo ($row['fname']. " " .$row['sname']) ?><br>
<small><?php echo ($row['position']) ?></small>
</h3>


<?php $no++;
}

}









share|improve this question















marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 21:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    We can't see line numbers. What is line 77?

    – Dharman
    Nov 20 '18 at 21:47






  • 1





    It isn't defined and you have a variable scope issue.

    – Funk Forty Niner
    Nov 20 '18 at 21:47






  • 1





    Pass $id as a parameter to the function.

    – Alex Howansky
    Nov 20 '18 at 21:47






  • 1





    @Dharman That edit of yours was unnecessary and modified code also; we can't do that. I rolled it back to Phil's revision.

    – Funk Forty Niner
    Nov 20 '18 at 21:54








  • 1





    You're open to an sql injection here btw. You really should use a prepared statement.

    – Funk Forty Niner
    Nov 20 '18 at 22:03














1












1








1









This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers




I am trying to list players into a page, the page already uses a sql query, so i have put this query in a function (below) which sitting in the functions.php, in another file teampage.php I have called the function <?php echo listGoalkeepersForTeam(); ?> , but it is throwing a Notice: Undefined variable: id in C:xampp***functions.php on line 77



how to get function to read the teampage.php?id=1 and display the information accordingly.



function listGoalkeepersForTeam() {

$dbServername = "****";
$dbUserrname = "****";
$dbPassword = "****";
$dbName = "****";

$sql = "select player.fname as fname, player.sname as sname, player.position as position, player.profile_img as profile_img from player_team
join player on player_team.player_id = player.player_id
join team on player_team.team_id = team.team_id
where team.team_id = '$id'
AND player.position = 'Goalkeeper'";


$conn = mysqli_connect($dbServername, $dbUserrname, $dbPassword, $dbName);
$query = mysqli_query($conn, $sql);

if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($query))
{ ?>

<img class="rounded-circle img-fluid d-block mx-auto mr-4" src="img/db_img/players/child.png" alt="<?php echo ($row['fname']. " " .$row['sname']) ?>">
<h3><?php echo ($row['fname']. " " .$row['sname']) ?><br>
<small><?php echo ($row['position']) ?></small>
</h3>


<?php $no++;
}

}









share|improve this question

















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers




I am trying to list players into a page, the page already uses a sql query, so i have put this query in a function (below) which sitting in the functions.php, in another file teampage.php I have called the function <?php echo listGoalkeepersForTeam(); ?> , but it is throwing a Notice: Undefined variable: id in C:xampp***functions.php on line 77



how to get function to read the teampage.php?id=1 and display the information accordingly.



function listGoalkeepersForTeam() {

$dbServername = "****";
$dbUserrname = "****";
$dbPassword = "****";
$dbName = "****";

$sql = "select player.fname as fname, player.sname as sname, player.position as position, player.profile_img as profile_img from player_team
join player on player_team.player_id = player.player_id
join team on player_team.team_id = team.team_id
where team.team_id = '$id'
AND player.position = 'Goalkeeper'";


$conn = mysqli_connect($dbServername, $dbUserrname, $dbPassword, $dbName);
$query = mysqli_query($conn, $sql);

if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($query))
{ ?>

<img class="rounded-circle img-fluid d-block mx-auto mr-4" src="img/db_img/players/child.png" alt="<?php echo ($row['fname']. " " .$row['sname']) ?>">
<h3><?php echo ($row['fname']. " " .$row['sname']) ?><br>
<small><?php echo ($row['position']) ?></small>
</h3>


<?php $no++;
}

}




This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    27 answers



  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers








php mysql function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 21:53









Funk Forty Niner

1




1










asked Nov 20 '18 at 21:44









Andy TerryAndy Terry

356




356




marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 21:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Funk Forty Niner mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 21:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    We can't see line numbers. What is line 77?

    – Dharman
    Nov 20 '18 at 21:47






  • 1





    It isn't defined and you have a variable scope issue.

    – Funk Forty Niner
    Nov 20 '18 at 21:47






  • 1





    Pass $id as a parameter to the function.

    – Alex Howansky
    Nov 20 '18 at 21:47






  • 1





    @Dharman That edit of yours was unnecessary and modified code also; we can't do that. I rolled it back to Phil's revision.

    – Funk Forty Niner
    Nov 20 '18 at 21:54








  • 1





    You're open to an sql injection here btw. You really should use a prepared statement.

    – Funk Forty Niner
    Nov 20 '18 at 22:03














  • 1





    We can't see line numbers. What is line 77?

    – Dharman
    Nov 20 '18 at 21:47






  • 1





    It isn't defined and you have a variable scope issue.

    – Funk Forty Niner
    Nov 20 '18 at 21:47






  • 1





    Pass $id as a parameter to the function.

    – Alex Howansky
    Nov 20 '18 at 21:47






  • 1





    @Dharman That edit of yours was unnecessary and modified code also; we can't do that. I rolled it back to Phil's revision.

    – Funk Forty Niner
    Nov 20 '18 at 21:54








  • 1





    You're open to an sql injection here btw. You really should use a prepared statement.

    – Funk Forty Niner
    Nov 20 '18 at 22:03








1




1





We can't see line numbers. What is line 77?

– Dharman
Nov 20 '18 at 21:47





We can't see line numbers. What is line 77?

– Dharman
Nov 20 '18 at 21:47




1




1





It isn't defined and you have a variable scope issue.

– Funk Forty Niner
Nov 20 '18 at 21:47





It isn't defined and you have a variable scope issue.

– Funk Forty Niner
Nov 20 '18 at 21:47




1




1





Pass $id as a parameter to the function.

– Alex Howansky
Nov 20 '18 at 21:47





Pass $id as a parameter to the function.

– Alex Howansky
Nov 20 '18 at 21:47




1




1





@Dharman That edit of yours was unnecessary and modified code also; we can't do that. I rolled it back to Phil's revision.

– Funk Forty Niner
Nov 20 '18 at 21:54







@Dharman That edit of yours was unnecessary and modified code also; we can't do that. I rolled it back to Phil's revision.

– Funk Forty Niner
Nov 20 '18 at 21:54






1




1





You're open to an sql injection here btw. You really should use a prepared statement.

– Funk Forty Niner
Nov 20 '18 at 22:03





You're open to an sql injection here btw. You really should use a prepared statement.

– Funk Forty Niner
Nov 20 '18 at 22:03












1 Answer
1






active

oldest

votes


















1














You are not getting the id from GET variable.



function listGoalkeepersForTeam() {
//insert line
$id = filter_input(INPUT_GET, 'id');
....





share|improve this answer
























  • this has seemed to work. many thanks Edwin.

    – Andy Terry
    Nov 20 '18 at 22:02











  • Can you mark the answer. As correct or not possible since its marked as duplicate?

    – Edwin Dijas Chiwona
    Nov 20 '18 at 22:03











  • i have marked it as correct and upvoted. its showing that on mine.

    – Andy Terry
    Nov 21 '18 at 15:45


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You are not getting the id from GET variable.



function listGoalkeepersForTeam() {
//insert line
$id = filter_input(INPUT_GET, 'id');
....





share|improve this answer
























  • this has seemed to work. many thanks Edwin.

    – Andy Terry
    Nov 20 '18 at 22:02











  • Can you mark the answer. As correct or not possible since its marked as duplicate?

    – Edwin Dijas Chiwona
    Nov 20 '18 at 22:03











  • i have marked it as correct and upvoted. its showing that on mine.

    – Andy Terry
    Nov 21 '18 at 15:45
















1














You are not getting the id from GET variable.



function listGoalkeepersForTeam() {
//insert line
$id = filter_input(INPUT_GET, 'id');
....





share|improve this answer
























  • this has seemed to work. many thanks Edwin.

    – Andy Terry
    Nov 20 '18 at 22:02











  • Can you mark the answer. As correct or not possible since its marked as duplicate?

    – Edwin Dijas Chiwona
    Nov 20 '18 at 22:03











  • i have marked it as correct and upvoted. its showing that on mine.

    – Andy Terry
    Nov 21 '18 at 15:45














1












1








1







You are not getting the id from GET variable.



function listGoalkeepersForTeam() {
//insert line
$id = filter_input(INPUT_GET, 'id');
....





share|improve this answer













You are not getting the id from GET variable.



function listGoalkeepersForTeam() {
//insert line
$id = filter_input(INPUT_GET, 'id');
....






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 21:53









Edwin Dijas ChiwonaEdwin Dijas Chiwona

35118




35118













  • this has seemed to work. many thanks Edwin.

    – Andy Terry
    Nov 20 '18 at 22:02











  • Can you mark the answer. As correct or not possible since its marked as duplicate?

    – Edwin Dijas Chiwona
    Nov 20 '18 at 22:03











  • i have marked it as correct and upvoted. its showing that on mine.

    – Andy Terry
    Nov 21 '18 at 15:45



















  • this has seemed to work. many thanks Edwin.

    – Andy Terry
    Nov 20 '18 at 22:02











  • Can you mark the answer. As correct or not possible since its marked as duplicate?

    – Edwin Dijas Chiwona
    Nov 20 '18 at 22:03











  • i have marked it as correct and upvoted. its showing that on mine.

    – Andy Terry
    Nov 21 '18 at 15:45

















this has seemed to work. many thanks Edwin.

– Andy Terry
Nov 20 '18 at 22:02





this has seemed to work. many thanks Edwin.

– Andy Terry
Nov 20 '18 at 22:02













Can you mark the answer. As correct or not possible since its marked as duplicate?

– Edwin Dijas Chiwona
Nov 20 '18 at 22:03





Can you mark the answer. As correct or not possible since its marked as duplicate?

– Edwin Dijas Chiwona
Nov 20 '18 at 22:03













i have marked it as correct and upvoted. its showing that on mine.

– Andy Terry
Nov 21 '18 at 15:45





i have marked it as correct and upvoted. its showing that on mine.

– Andy Terry
Nov 21 '18 at 15:45





Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?