drayarms Posted May 26, 2011 Share Posted May 26, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/237518-error-message-when-i-attempt-to-pass-variables-to-another-page/ Share on other sites More sharing options...
hemo-ali Posted May 26, 2011 Share Posted May 26, 2011 Try this code header("Location: search_results.php?friend='$row[member_id]'&me='$_SESSION[id]'&pic='$row[image]'&name='$row[username]'"); Quote Link to comment https://forums.phpfreaks.com/topic/237518-error-message-when-i-attempt-to-pass-variables-to-another-page/#findComment-1220532 Share on other sites More sharing options...
KevinM1 Posted May 26, 2011 Share Posted May 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237518-error-message-when-i-attempt-to-pass-variables-to-another-page/#findComment-1220533 Share on other sites More sharing options...
Adam Posted May 26, 2011 Share Posted May 26, 2011 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'].'"); Quote Link to comment https://forums.phpfreaks.com/topic/237518-error-message-when-i-attempt-to-pass-variables-to-another-page/#findComment-1220535 Share on other sites More sharing options...
drayarms Posted May 26, 2011 Author Share Posted May 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237518-error-message-when-i-attempt-to-pass-variables-to-another-page/#findComment-1220829 Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 Forgot a semicolon somewhere, probably. Quote Link to comment https://forums.phpfreaks.com/topic/237518-error-message-when-i-attempt-to-pass-variables-to-another-page/#findComment-1220843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.