Log in

View Full Version : Help With Defining Null/Not Null



X96 Web Design
07-04-2009, 04:00 AM
I'm making a script, that checks a MySQL database for content for a page (depending on what the value of the GET is.), and I'm having a bit of trouble with it....
Here's my PHP:


$getpage = $_GET['page'];
$sqlz = mysql_query("SELECT * FROM pages WHERE `slug` = '$getpage'");
$sql = mysql_query("SELECT * FROM pages WHERE `slug` = '$getpage'");
if($sqlz != null){
global $sqlz;
global $sql;
function the_title() {
global $sqlz;
while($row = mysql_fetch_array($sqlz)){
echo $row[0];
}
}
function the_content() {
global $sql;
while($rowz = mysql_fetch_array($sql)){
echo $rowz[1];
}
}
}
else {
function the_content(){
echo '<p>The page you have requested could not be found!</p><p>Make sure that...</p><ul><li><strong>If you typed the URL yourself</strong>, all words are spelled correctly, and the page actually exists</li><li><strong>If you clicked on a link from a <em>different site</em></strong>, the link may be outdated. Please contact the owner of the site and inform them</li><li><strong>If you clicked on a link in <em>this site</em></strong>, please <a href="?page=contact">tell us</a> about it.</li></ul>';
}
function the_title(){
echo '404 - Page Not Found';
}
}


And here's the HTML:


<h1><?php the_title(); ?></h1>
<?php the_content(); ?>

<div class="clear"></div>


I can get it to display the page, but if the page isn't found, it just shows whitespace, and not what I've defined in the ELSE...

Any help or suggestions would be greatly appreciated!

// X96 \\

X96 Web Design
07-06-2009, 12:27 AM
Never Mind... I figured it out myself. Here's my code now:


$getpage = $_GET['page'];
$sqlz = mysql_query("SELECT * FROM pages WHERE `slug` = '$getpage'");
$sqlzy = mysql_query("SELECT * FROM pages WHERE `slug` = '$getpage'");
$sql = mysql_query("SELECT * FROM pages WHERE `slug` = '$getpage'");
if(mysql_num_rows($sqlz) == 0){
function the_content(){
echo '<p>The page you have requested could not be found!</p><p>Make sure that...</p><ul><li><strong>If you typed the URL yourself</strong>, all words are spelled correctly, and the page actually exists</li><li><strong>If you clicked on a link from a <em>different site</em></strong>, the link may be outdated. Please contact the owner of the site and inform them</li><li><strong>If you clicked on a link in <em>this site</em></strong>, please <a href="?page=contact">tell us</a> about it.</li></ul>';
}
function the_title(){
echo '404 - Page Not Found';
}
}
else{
global $sqlz;
global $sql;
function the_title() {
global $sqlz;
while($row = mysql_fetch_array($sqlz)){
echo $row[0];
}
}
function the_content() {
global $sql;
while($rowz = mysql_fetch_array($sql)){
echo $rowz[1];
}
}
function thetitle() {
global $sqlzy;
while($rowy = mysql_fetch_array($sqlzy)){
echo $rowy[0];
}
}
}
function sitename(){
$sql3 = mysql_query("SELECT * FROM system LIMIT 1");
while($row3 = mysql_fetch_array($sql3)){
echo $row3[0];
}
}