Error message when I attempt to pass variables to 2nd page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

Error message when I attempt to pass variables to 2nd page.

Post by drayarms »

I want to query a database (search) and pass the desired columns from the search results to another page like so:

Code: Select all

<?php

//address error handling

ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);


//authenticate user
require('auth.php');


if (isset($_POST['submit'])) {

	// Connect to the database.

        require_once ('config.php');


	//Query the database.
	$sql = "SELECT* FROM members INNER JOIN images ON members.member_id = images_member_id WHERE members.ethnicity = '{$_POST['ethnicity']}'";

	$query = mysql_query($sql);
	
	if(mysql_num_rows($query) > 0){ while(($row = mysql_fetch_assoc($query)) !== false)
					         
		{

		//Redirect to search results page.

		header("Location: search_results.php?friend='.$row['member_id'].'&me='.$_SESSION['id'].' &pic='.$row['image'].'&name='.$row['username'].'");
		
		}

	} else { //If no results found.

		echo 'No results match this search query.' ;

		}

}



?>
 
I get the following error when i try to run the page (by submitting a form from another page which executes this page):

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a4993450/public_html/profile_search.php on line 31

The culprit line is this one:
header("Location: search_results.php?friend='.$row['member_id'].'&me='.$_SESSION['id'].' &pic='.$row['image'].'&name='.$row['username'].'");

As you can see, I eliminated all white space between the variables and concatenations, thinking that that was the problem but I keep getting the error message. I'm at a loss about what to do next. Any help?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Error message when I attempt to pass variables to 2nd pa

Post by Celauran »

drayarms wrote:The culprit line is this one:

Code: Select all

header("Location: search_results.php?friend='.$row['member_id'].'&me='.$_SESSION['id'].' &pic='.$row['image'].'&name='.$row['username'].'");
It is indeed.

Notice how you're opening with a double quote but then attempting to close with a single quote. Properly match your quotes and the problem goes away.

Code: Select all

header("Location: search_results.php?friend=" . $row['member_id'] . "&me=" . $_SESSION['id'] . "&pic=" . $row['image'] . "&name=" . $row['username']);
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

Re: Error message when I attempt to pass variables to 2nd pa

Post by drayarms »

After trying all your suggestions, I now get this error message:

Parse error: syntax error, unexpected T_VARIABLE in /home/a4993450/public_html/profile_search.php on line 47. Clearly the query is working but the syntax on the redirect line just isnt right.
Post Reply