0

I'm running a script that fetches a row from a MySQL table and is supposed to then pass certain variables from that row to the next page to be used in a form that allows user updating.

Here's the excerpt from the script that is trying to pass the variables to the next page:

if ($row['home_score'] == '0' && $row['away_score'] == '0') {
        echo '<td><a href="report_score.html?league=test_league&game_id=" . $row['game_id']"><img src="images/report_icon.png" alt="Report Score" /></a></td>';        
    }

If I omit everything after "&game_id=" in the href, it displays fine. However, once I start adding the variables, it cuts off the function and stops displaying the page.

Am I doing something simple wrong with the syntax? I've tried playing around with different ways to write it, but to no avail. Do I need to utilize a http_build_query() to make this work?

Here's the entire script code if you need more info:

<?php

// Connect to the database:
require ('../mysqli_connect.php');

// Make the query for games from the schedule database and determine the game location:
$q = "SELECT tl.game_date, tl.game_time, tl.away_team, tl.home_team, tl.home_score,tl.away_score, tl.arbiter_id, us.football_location, us.football_map 
FROM test_league tl
    INNER JOIN user_schools us ON (tl.home_team = us.school_name)
ORDER BY tl.game_id";
$r = mysqli_query($db, $q);

// Declare two variables to help determine the background color of each row:
$i = 0;
$bgcolor = array('row1', 'row2');

// Begin function to print each game as a row:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

    echo '<tr class="' . $bgcolor[$i++ % 2] .'"><td>' . $row['game_date'] . '</td><td>' . $row['game_time'] . '</td><td class="alignleft"><a href="">' . $row['away_team'] . '</a> vs<br><a href="">' . $row['home_team'] . '</a></td>';

    // Determine if the score has been reported:
    if ($row['home_score'] == '0' && $row['away_score'] == '0') {
        echo '<td><a href="report_score.html?league=test_league&game_id=" . $row['game_id']"><img src="images/report_icon.png" alt="Report Score" /></a></td>';        
    } else {
        echo '<td>' . $row['home_score'] . '<br>' . $row['away_score'] . '</td>';
    }

    echo '<td><a href="' . $row['football_map'] . '" target="_blank">' . $row['football_location'] . '</a></td><td><a href="">' . $row['arbiter_id'] . '</a></td></tr>';

}

mysqli_free_result ($r);

mysqli_close($db);

?>

Any and all advice is greatly appreciated!

3
  • try urlencode to encode your variables when adding them to the href Commented Sep 4, 2013 at 20:44
  • 1
    You are missing the . for string concatenation after your $row['game_id'] Commented Sep 4, 2013 at 20:46
  • 2
    instead of " . $row['game_id']", should be: game_id='.$row['game_id'].' single quote and missing dot. Commented Sep 4, 2013 at 20:47

2 Answers 2

1

Try this, you've got your speech marks and dots mixed up :)

if ($row['home_score'] == '0' && $row['away_score'] == '0') {
    echo '<td><a href="report_score.html?league=test_league&game_id=' .$row['game_id']. '"><img src="images/report_icon.png" alt="Report Score" /></a></td>';        
}

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, everyone, for your feedback. I goofed and omitted much of the string I was trying to pass in the code (hence, the missing dot), but the real issue was the use of double quotations instead of single. Correcting that solved the problem. Much appreciated!
1
$url = 'www.example.com?' . http_build_query($row,'','&amp;');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.