6 Replies - 6514 Views - Last Post: 27 May 2011 - 01:18 PM Rate Topic: -----

#1 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 177
  • Joined: 18-May 11

Error message when I attempt to pass variables to another page

Posted 26 May 2011 - 04:10 AM

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):

Quote

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?

This post has been edited by Dormilich: 26 May 2011 - 04:33 AM
Reason for edit:: pretty print formatting


Is This A Good Question/Topic? 0
  • +

Replies To: Error message when I attempt to pass variables to another page

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Error message when I attempt to pass variables to another page

Posted 26 May 2011 - 04:19 AM

You need to put braces {} around your arrays like $row and $_SESSION.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Error message when I attempt to pass variables to another page

Posted 26 May 2011 - 06:20 AM

//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);

// You should check for success here.
if(!$query)
{
    trigger_error("SQL query $sql failed: " . mysql_error(), E_ERROR);
    // Handle as desired
}
else
{	
    if(mysql_num_rows($query) > 0)
    { 
        while(($row = mysql_fetch_assoc($query)) !== false)
        {
            // This logic doesn't make sense. 
            // What if more than one result comes back as it surely will?

            //Redirect to search results page.
            $redirect = 'Location: search_results.php?friend=' . $row['member_id'] . '&me=' . $_SESSION['id'] . '&pic=' . $row['image'] . '&name=' . $row['username'];
            header($redirect);
        }

    } 
    else 
    { 
        //If no results found.
        echo 'No results match this search query.' ;
    }
}


Was This Post Helpful? 0
  • +
  • -

#4 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 177
  • Joined: 18-May 11

Re: Error message when I attempt to pass variables to another page

Posted 26 May 2011 - 01:44 PM

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.
Was This Post Helpful? 0
  • +
  • -

#5 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Error message when I attempt to pass variables to another page

Posted 27 May 2011 - 06:08 AM

You're missing either a dot (.), a semi-colon (;) or a brace ({}) somewhere in your code. We can't see your code from where to know what's causing the error.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Error message when I attempt to pass variables to another page

Posted 27 May 2011 - 07:02 AM

You should really address the comment I made here as well:

while(($row = mysql_fetch_assoc($query)) !== false)
{
    // This logic doesn't make sense. 
    // What if more than one result comes back as it surely will?

    //Redirect to search results page.
    $redirect = 'Location: search_results.php?friend=' . $row['member_id'] . '&me=' . $_SESSION['id'] . '&pic=' . $row['image'] . '&name=' . $row['username'];
    header($redirect);
}

Was This Post Helpful? 0
  • +
  • -

#7 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 177
  • Joined: 18-May 11

Re: Error message when I attempt to pass variables to another page

Posted 27 May 2011 - 01:18 PM

@jackofalltrades. Well I'm actually expecting more than one result. It is a search query that expects to return multiple results based on the criterion selected, in this case, ethnicity. Anyway I edited that line you pointed out to

while(($row = mysql_fetch_assoc($query)) ){// Redirect to search results page.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1