Script 17.5
PHP and MySQL for Dynamic Web Sites: The Forum!
English/English
Byttet til PHP 5.0 fra PHP 4.0 - variabler utilgjengelige
Silje (29-Oct-11 4:15 AM)
Jeg har nettopp gått over til PHP 5.0 og forsøkte å benytte meg av mine gamle scripts. Dette viste seg å være noe vanskelig ettersom de bare generer feil. Hovedproblemet virker å være at jeg ikke får tilgang til variabler som tidligere var tilgjengelige. Noen som har noen forslag?
troutster (29-Oct-11 4:20 AM)
Har du sjekket om variablene du prøver å få tilgang på er superglobals? Dette forandret seg fra 4.2 og utover, tror jeg...
João (29-Oct-11 4:30 AM)
Hva er superglobals?
kiwi (29-Oct-11 10:26 AM)
Linken Terje ga er manualsiden, men du kan også ta en titt på http://www.linuxjournal.com/article/6559 for en grundig innføring og forklaring. Lykke til!
troutster (30-Oct-11 6:16 AM)
http://no.php.net/variables.predefined
You must be logged in to post messages.
<?php # Script 17.5 - thread This page shows the messages in a thread. include (CHAPTER_PATH.'/'.$chapter.'/includes/17.1.php'); // Check for a thread ID... $tid = FALSE; if (isset($_GET['tid']) && filter_var($_GET['tid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { // Create a shorthand version of the thread ID: $tid = $_GET['tid']; // Convert the date if the user is logged in: if (isset($_SESSION['tz'])) { $posted = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['tz']}')"; } else { $posted = 'p.posted_on'; } // Run the query: $q = "SELECT t.subject, p.message, username, DATE_FORMAT($posted, '%e-%b-%y %l:%i %p') AS posted FROM mb_threads AS t LEFT JOIN mb_posts AS p USING (thread_id) INNER JOIN mb_users AS u ON p.user_id = u.user_id WHERE t.thread_id = $tid ORDER BY p.posted_on ASC"; $r = mysqli_query($link, $q); if (!(mysqli_num_rows($r) > 0)) { $tid = FALSE; // Invalid thread ID! } } // End of isset($_GET['tid']) IF. if ($tid) { // Get the messages in this thread... $printed = FALSE; // Flag variable. // Fetch each: while ($messages = mysqli_fetch_array($r, MYSQLI_ASSOC)) { // Only need to print the subject once! if (!$printed) { echo "<h2>{$messages['subject']}</h2>\n"; $printed = TRUE; } // Print the message: echo "<p>{$messages['username']} ({$messages['posted']})<br />{$messages['message']}</p><br />\n"; } // End of WHILE loop. // Show the form to post a message: include (CHAPTER_PATH.'/'.$chapter.'/includes/17.6.php'); } else { // Invalid thread ID! echo '<p>This page has been accessed in error.</p>'; } include (CHAPTER_PATH.'/'.$chapter.'/includes/17.2.php'); ?>