Jump to content

Error message when I attempt to pass variables to another page


drayarms

Recommended Posts

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

<?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?

 

Link to comment
Share on other sites

Almost.  Use:

 

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

 

Array indices which are strings need to be denoted as such by being placed in quotes.  Array values you want to parse in a double-quoted string need to be placed in curly braces.

Link to comment
Share on other sites

Use Nightslyr's suggestion as it's cleaner and easier to read. Your original problem for future reference though, was that you were trying to close and re-open a double-quote string using a single quote:

 

header("Location: search_results.php?friend='.$row['member_id'].'&me='.$_SESSION['id'].' &pic='.$row['image'].'&name='.$row['username'].'");
Link to comment
Share on other sites

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.

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.