Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Having trouble carrying over key id from one page to the next

Featured Replies

I’m trying to make this link work. The first page makes a list of bands. Each has a hyperlink to a page based on their band_id (key value of band_members table).

 

The first page displays correctly and the link looks correct in the new page:

http://localhost/bandinfo.php?id=31

 

where id=31 changes correctly depending on the artist clicked on.

 

My code in the bandinfo.php page is not picking up the id value. The page will display correctly if I force the code to be id=31. How do I include the id from the previous page in this code?

 

Thanks for any help...

 

Page 1: artists.php

 

$page_title = 'Artists';

require_once ('../mysqli_connect.php'); // Connect to the db.

 

$q = "SELECT band_id, genera, band_name, music_description FROM band_members ORDER BY genera , band_name";

$r = mysqli_query($dbc, $q);

 

$currentGenre = '';

while ($messages = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

if ($currentGenre != $messages['genera']) {

echo "<h2>{$messages['genera']}</h2>\n";

$currentGenre = $messages['genera'];

}

echo "<a href=bandinfo.php?id={$messages['band_id']}><h5>    {$messages['band_name']}</h5></a><br />         {$messages['music_description']}<br /><br />\n";

 

}

mysqli_free_result ($r);

mysqli_close($dbc); // Close the database connection.

 

 

 

Page 2: bandinfo.php:

session_start();

$page_title = 'Band Details';

require_once ('../mysqli_connect.php');

$q = "SELECT band_name AS bn, genera AS g, music_description AS md, biog AS b, gig_history AS gh, gig_future AS gf, reviews AS re FROM band_members WHERE band_id='$id'";

$r = @mysqli_query ($dbc, $q);

if ($r) { // If it ran OK, display the records.

// Fetch and print all the records:

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

 

echo stripslashes(nl2br($row['bn']));

 

echo stripslashes(nl2br($row['g']));

 

echo '<h1>News</h1>';

echo stripslashes(nl2br($row['md']));

}

 

mysqli_free_result ($r);

} else {

error messages …

Depending on your version of PHP, you may need to tell it specifically to get the ID from the URL and place it into a variable.

 

In Page 2, stick this in before your SQL query.

 

$id = ($_GET['id']);

 

I find it's a good habit to do this whatever version/setup you're running. Just in case.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.