Jump to content

Recommended Posts

Hi,

 

 

I made a bit of code that would get a pages title and content from a database, however every time i put this bit of code into the file, and upload that file, i then get an "Internal Server Error (500)". Whereas if i take the code out, and uplaod the file - the webpage is fine?

 

 


					<?php

						$sql = "SELECT * FROM pages WHERE title = '$page'";
						$res = mysql_query($sql);

						if($row = mysql_fetch_assoc($res)
						{
							$title = $row["title"];
							$content = $row["content"];

							echo "<h1>".$title."</h1>";
							echo $content;
						}
						else
						{
							echo "<h1>Oops...</h1>";
							echo "<p>This page doesn't appear to exsist!</p>";
							echo "<p>Use the 'Quick Contact' box to contact the webmaster and tell them about the page you are requesting.</p>";
						}

					?>

 

 

Not sure where ive gone wrong.

On this line:

 

if($row = mysql_fetch_assoc($res)

 

You are missing the closing if ) it should be:

 

if($row = mysql_fetch_assoc($res))

 

If you had display_errors on, it should have alerted you of the error vs just 500ing. You could also check the apache error logs, if php is set to log to it.

the connection is established in "connect.php".

 

 

thanks premiso the page is now displaying however its is now echoing the "else" statement - the rows that were specified do actually exsist in the database. and they have content.

 

 

http://tutorials.janedealsart.co.uk <-- This is the "else" statement im getting.

cleaned up your code snippet let us know if it works any better.

 


<?php
$page= $_POST['page'];

$sql = 'SELECT * FROM pages WHERE title = "'.$page.'"';
$res = mysql_query($sql);

while($row = mysql_fetch_assoc($res)){
$title = $row["title"];
$content = $row["content"];
echo "<h1>".$title."</h1>";
echo $content;


}

if(mysql_num_results($row)===0) {
echo "<h1>Oops...</h1>";
echo "<p>This page doesn't appear to exsist!</p>";
echo "<p>Use the 'Quick Contact' box to contact the webmaster and tell them about the page you are requesting.</p>";
}

Anyway - a few errors poped up with your code, however i fixed them and my problem is solved.

 

 

Fixed code:

 

 

<?php


   include "sql/conf.php";
   include "sql/connect.php";


   $page = "Welcome";


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[url=http://www.w3.org/TR/html4/loose.dtd]http://www.w3.org/TR/html4/loose.dtd[/url]">
<html>
   <head>
      <title><?php echo $GLOBALS["siteName"]." - ".$page; ?></title>
      <link rel="stylesheet" type="text/css" href="css/main.css">
      <link rel="stylesheet" type="text/css" href="css/sub-css.css">
      <link rel="stylesheet" type="text/css" href="css/tags.css">
   </head>
   <body>
      <div class="wrapper">
         <div class="header">
            <div class="head">
               <img src="images/logo.png" alt="HTML Bites Logo">
            <>
         <>
         <div class="sub-wrapper">
            <div class="navigation">
               <div id="navigation">
                  <a href="index.php">Home</a>
                  <a href="#">News</a>
                  <a href="#">Gallery</a>
                  <a href="#">Tutorials</a>
                  <a href="#">Downloads</a>
                  <a href="#">Contact</a>
               <>
            <>
            <div class="content">
               <div class="center-column">                  
                  <?php
                     
                     //$page_name = $_POST['page'];


                     $sql = 'SELECT * FROM pages WHERE title = "'.$page.'"';
                     $res = mysql_query($sql);


                     while($row = mysql_fetch_assoc($res))
                     {
                        $title = $row["title"];
                        $content = $row["content"];
                        echo "<h1>".$title."</h1>";
                        echo $content;
                     }
                        
                     if(mysql_num_rows($res) == 0)
                     {
                        echo "<h1>Oops...</h1>";
                        echo "<p>This page doesn't appear to exsist!</p>";
                        echo "<p>Use the 'Quick Contact' box to contact the webmaster and tell them about the page you are requesting.</p>";
                     }
                     
                  ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.