Jump to content

Passing two variables via URL but not able to GET one of them...


Jim R

Recommended Posts

I'm creating this URL to pass variables to use from one Page to another:

 

http://eg10basketball.com/playerinfo/?nameFull=Evan-Borgman&team=16

 

 

My WP site is seeing the first variable but not the second.  After some searching I've found this suggestion, but it's not working for me:

function add_query_vars_filter( $vars ) {

	$vars[] = "nameFull";
	$vars[] = "team";

	return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );

I tried putting this in the wp-includes/functions.php file of the, but ended up with a fatal error.  I have since added it to my theme's functions.php file. There isn't an error, but it doesn't yield recognition of my second variable. 

 

 

Link to comment
Share on other sites

I have two areas drawing information my database based on the variables passed from a Roster Page to a Profile Page.  On the Profile Page, there are two queries, one in main/body and one in the sidebar.  The main/body area is working.  The sidebar isn't.  

 

Below the:  echo $team produces nothing.

 

 

Here is the page in question:

 

http://eg10basketball.com/playerinfo/?nameFull=Evan-Borgman&team=16

 

 

Here is the error I'm getting:

 

 

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home4/jwrbloom/public_html/eg10basketball.com/resources/roster-widget.php on line 14
$team = $_GET['team'];
echo $team;	
	
$query = 'SELECT * FROM a_players WHERE team= '. $team .' ORDER BY nameLast ASC';
$results = mysql_query($query);
$count = 0;
while($line = mysql_fetch_assoc($results)) {


$count = $count+1;

	echo '<div><a href="http://eg10basketball.com/playerinfo?nameFull=' . $line['nameFirst'] . '-' . $line['nameLast'] . '">'. $line['nameFirst'] . ' ' . $line['nameLast'] .'</a><br></div>';

}
Link to comment
Share on other sites

Would it make any difference that the second variable is a number?  I tested it by removing the first variable, 'nameFull', and 'team' alone doesn't produce any results.  So under no circumstance does it pass the team number to the second page, even though it clearly passes the team number 16 to the second page's URL.

Link to comment
Share on other sites

So what happens when you echo $_GET['nameFull']; and echo $_GET['team'];

 

What info does it show? Also what does the $query look like? Perhaps echo $query also to see what SQL is being created? Are you certain team isn't being passed and the query has another type of error?

 

edit: sorry just noticed you echoing $team already. but would be interested to see what is in nameFull when echoed.

Edited by wezhind
Link to comment
Share on other sites

$team = $_GET['team'];
echo $team;    
    
$query
= 'SELECT * FROM a_players WHERE team= '. $team .' ORDER BY nameLast ASC';
$results = mysql_query($query);
$count = 0;
while($line = mysql_fetch_assoc($results)) {


I cleaned up your code a little bit.

<?php

$team = mysql_escape_string($_GET['team']);

if(is_int($team)){
  $query = "select `nameFirst`, `nameLast` from `a_players` where 'team' = '{$team}' order by nameLast asc";
  $results = mysql_query($query);
  $count = 0; //why are you counting if you mind me asking
  while($player = mysql_fetch_assoc($results)) {
    $nameFirst = $player['nameFirst'];
    $nameLast = $player['nameLast'];
    echo <<<EOT

    <div>
      <a href="http://eg10basketball.com/playerinfo?nameFull={$nameFirst}-{$nameLast}">{$nameFirst} {$nameLast}</a>
      <br>
    </div>

EOT;

  }
}
Link to comment
Share on other sites

When I echo $playerName it show (in the case of this page) Evan-Borgman.  I have flipped flopped the GET's.  $_GET('nameFull') always works, $_GET('team') never works.  I keep looking to make sure it isn't some syntax error.  

 

 

@chriscloyd, I'll have to try that out after a meeting.  I wanted to answer the question of what shows up when I echo nameFull.  I'll have to keep the SELECT * though because I'll be adding more information to the printout.  That was just a quick port from another instance where it was just a list of names.

 

 

Does it matter that I have two GETs on the page?  My instinct says no, and I did flip flop the GET's (instances) on my page with the same result.

 

 

Here is the side that is working:

$playerName = $_GET['nameFull'];

//echo $playerName;
 
	

$query = 'SELECT * FROM a_players ORDER BY uniform ASC';
$results = mysql_query($query);

while($line = mysql_fetch_assoc($results)) {
	
	$nFirst = $line['nameFirst'];
	$nLast = $line['nameLast'];
	$nameFull = "{$nLast}{$nFirst}";

	if ($playerName == $line['nameFirst'].'-'.$line['nameLast']) {

	echo '
	
	<div class="profile">';
	
	echo '<div class="profileName">' .$line['nameFirst'] . ' ' .$line['nameLast'] . '</div>';
	
	echo '<div>'. $line['feet'] . '\'' . $line['inches'] . '", ';
	
		 	if ($line['position'] == 'PG')  {echo 'Point Guard';}
		elseif ($line['position'] == 'SG')  {echo 'Shooting Guard';}
		elseif ($line['position'] == 'SF')  {echo 'Small Forward';}
		elseif ($line['position'] == 'PF')  {echo 'Power Forward';}
		elseif ($line['position'] == 'C')  {echo 'Center';}
	
	 echo '</div>';

	//echo '<img src="http://spieceindyheat.com/2015/images/player_boards/hardwoodBW/' .  strtolower($nLast) .'' . $line['nameFirst'] . '.png" width="250">';
	echo '<div>Class of 20' . $line['team']. '</div>';
	echo '<div>';
	
	if (!isset($line['city'])) {
	echo $line['school'] .' HS';
	}
else 
	{
	echo $line['city'] . ' ('. $line['school'] . ')';
	}
	
	
	echo '</div><!--more-->';
	
	if ($line['team'] < 19) {
	echo '<div>Coach ' . $line['coachSchool'].'</div>';
	}
//	echo $line['schoolAddress'] . '<br>';
//	echo $line['schoolCity'] . ' IN, ' . $line['schoolZip'] . '<br>';
//	echo $line['schoolPhone'];	
	echo '</div>
	
	<hr class="profile">';
		
	}
}
Link to comment
Share on other sites

(Thank you for unlocking the topic.)

 

I tried the global GET:  it produced 

Array
(
    [nameFull] => Evan-Borgman
   
)

Interestingly, I read something somewhere that said to add %26 (numerical ampersand value), and this is what I got:

Array
(
    [nameFull] => Evan-Borgman
    [&team] => 16
)

So I changed the top of the code to:

 

$team = $_GET['&team'];

echo $team;
 
 
And it produced the correct 16.
 
 
However, it's still not taking $team = 16 and using it in the query.  
Link to comment
Share on other sites

Always start off looking at the total $_GET variable and not the individual elements.  Use one of the following:

var_dump($_GET);
print_r($_GET);
echo('<pre>'.print_r($_GET,1).'</pre>');  //Better for humans to read

Evidently, your URL is not well formed.  Look into urlencode().

He is using wordpress, which restricts/filters $_GET, which is why this seeminhly easy problem is a bit more complex since it appears the global $_GET is being manipulated.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Hi. Been away for a while. Not sure of the status of this issue. However, if as CroNiX mentioned a couple of posts back, the $_GET variable is being manipulated, you could 'cheat' and send your info serialised in some manner.

Rough example: I don't know the maximum value that your team variable will reach, but say it's under a thousand then you could format the team to be a 4 digit string and add that to your nameFull info i.e. '0016EvanBorger' and then use substr() to split the string into the 2 values you require.

 

I know hardly anything about the workings of WordPress, but is it possible that it only allows one 'value' in the $_GET variable. Does it use a serialise type method to pass variables using the $_GET itself? I don't know... it just popped into my head as a possibility.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.