Jump to content

Recommended Posts

navpath.php

<br><br><img src='./images/nav.png'> <a href='./index.php?act=idx'><? echo FORUM_NAME; ?></a>
<?
    if ($act != idx) {
    if ($act == viewforum) {
        $forumId = $_GET['forumid'];
        $PathQuery = "SELECT * FROM "+FORUM_NAME_TABLE+" WHERE forum_id='"+$forumId+"'";
        $PathResult = mysql_query($PathQuery, $db);
        $CatID = mysql_result($PathResult, 0, 'cat_id');
        $ForumTitle = mysql_result($PathResult, 0, 'forum_name');
        $CatQuery = "SELECT cat_name FROM "+FORUM_CAT_TABLE+" WHERE cat_id='"+$CatID+"'";
        $CatResult = mysql_query($CatQuery, $db);
        $CatName = mysql_result($CatResult, 0, 'cat_name');
        ?>
        · <a href='./index.php?act=viewcat&catid="<? echo $CatID; ?>"'> <? echo $CatName; ?>
        · <a href='./index.php?act=viewforum&forumid="<? echo $forumId; ?>"'><? echo $ForumTitle; ?>
            <?
    }

This is meant to select the information from the address bar with $_GET and then read relavent information from the db.

 

Basically what i'm doing is making a forum system from scratch using 1 file that users will access. Heres the index page:

 

<?php include("headers.php"); ?>

<table width="760" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#979797" height="100%" bordercolor="#000000" bordercolordark="#000000" bordercolorlight="#000000">
<tr> 
<td width="100%" height="100%" bgcolor="979797" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#000000" valign="top">
    
<!-- Header/Logo Section -->
<div id="logostrip">
    <center><a href="./index.php?act=idx"><img src="./images/logo.png" alt="Forum Index" Border="0"></a></center>
</div>
<!-- End Head/Logo -->
        
<!-- Navigation -->      
<?php include("navigation.php"); ?>
<!-- End Navigation -->
<div align='center' style='margin-bottom:3px;'></div>

<!-- User Nav -->
<?php include("usernav.php"); ?>

<!-- Navigation Path -->
<?php include("navpath.php"); ?>
</td>
</tr>
</table>
</body>
</html>
<?php
mysql_close($db);
?>

 

Headers.php


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<?php
session_start();
//Connect to Database and Check cookies for logged in user
require_once('_connect.php');
if (!isset($_GET['act'])) {
    if (!isset($_POST['act'])) {
        $act = 'idx';
    }
    if (isset($_POST['act'])) { 
        $act = $_POST['act']; 
    }
}
if (isset($_GET['act'])) { $page = $_GET['act']; }
if (isset($_SESSION['SESS_MEMBER_ID'])) {
    $memid = $_SESSION['SESS_MEMBER_ID'];
}
if (isset($memid)) {
    $db = mysql_connect(MSQL_HOST, MYSQL_USER, MYSQL_PASS);
    mysql_select_db(MYSQL_DB_NAME);
    $query_meminfo = "SELECT * FROM " + MYSQL_DB_NAME + "." + MYSQL_PROFILE_TABLE + " WHERE `user_id`="+ $memid;
    $query_result = mysql_query($db, $query_meminfo);
    $MemName = mysql_result($query_result, 0, 'display_name');
    $MemGroup = mysql_result($query_result, 0, 'Group');
}

?>
<html>
<head>
    <title>Rayth ..::Forum::..</title>
        <?php include("style.php"); ?>
    <base href="http://rayth.eyes2design.com/" />
</head>
<body text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="3" topmargin="3" marginwidth="3" marginheight="0" bgcolor="979797">

 

_connect.php

<?php
//_connect.php contains all information for all databases
//MySQL Login Information
    define('MYSQL_HOST', 'localhost');
    define('MYSQL_USER', 'xxxxxxxxxx');
    define('MYSQL_PASS', 'xxxxxxxxxx');
    define('MYSQL_DB_NAME', 'rayth');
    
    //Member Stuff (Forum/Member Section Tables)
    define('MEMBER_LOGIN_TABLE', 'user_login'); //Contains Username, Password and ID Number ONLY
    define('MEMBER_PROFILE_TABLE', 'user_profile'); //Contains ID, Username, Forum Posts, Avatar, Email Address , Rank, BlogID, signature
    define('MEMBER_GROUPS', 'user_groups'); //group list
    //Forum Settings
    define('FORUM_CAT_TABLE', 'forum_cat'); //All Forum Categories (ID, Title)
    define('FORUM_NAME_TABLE', 'forum_names'); //All Forums EXCEPT SUB FORUMS (ID, Title, Description, CatID, Permission [PostLevel, ReplyLevel, ViewLevel - 2 = Admin, 1 = Logged In, 0 = Guest])
    define('FORUM_THREADS', 'forum_threads'); //Contains all Forum Thread (Title, ID, CreatorID)
    define('FORUM_POSTS', 'forum_posts'); //Contains ALL forum posts. PostID, ThreadID, PosterID,  Message, Time/Date, 
    define('FORUM_NAME', 'Rayth Forum');
?>

 

What it is doing so far is everything in index.php/headers.php and then when it gets to navpath.php it only displays the forum name with the initial image. Why won't it get the whole navigation path if I use adress.com/index.php?act=viewforum&forumid=1

Link to comment
https://forums.phpfreaks.com/topic/249649-cant-seem-to-get-this-working/
Share on other sites

I Don't have access to php.ini to see if they are on. Is there a way to set it per script?

 

Also idx is the way index.php knows what to display once I get it so the address would be index.php?act=idx OR act=something (As shown in headers.php)

You can set error reporting per script with this, it won't work if there's a fatal parse error.

ini_set('display_errors', 'On');
error_reporting(-1);

 

In these 2 lines, you're comparing the value of a variable to the value of a constant. To compare to string values, they'd need to be quoted. In most cases, if a comparison is done in that manner, php is smart enough to realize that no constant is defined by that name, and juggles it to a string comparison, but that takes time, and it can cause major headaches if a constant actually is defined by that name.

 

if ($act != idx) {
    if ($act == viewforum) {

 

Consider what happens in this scenario:

 

config.php

<?php
//site constants
define( 'idx', 'index.php');

 

index.php

<?php
require_once( 'config.php' );

// incoming $_GET['page'] = 'idx'

if( $_GET['page'] == idx ) {
     // do something
}

 

The above comparison will return FALSE even though $_GET['page'] = 'idx' because it's being compared to value of the constant idx.

Ok I fixed the code so the different parts are quoted (ie $act != 'idx') and then turned errors on. The following errors were returned on index.php?act=viewforum&forumid=1

 

Notice: Undefined variable: act in /home/rayth/public_html/navpath.php on line 7

 

Notice: Undefined variable: act in /home/rayth/public_html/navpath.php on line 8

 

Notice: Undefined variable: act in /home/rayth/public_html/navpath.php on line 22

 

Notice: Undefined variable: db in /home/rayth/public_html/index.php on line 33

 

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/rayth/public_html/index.php on line 33

 

both variables act and db are defined in headers.php which is the first file included in index.php

Ok I fixed that problem with the variable and now Apparently there is a problem with the last 2 lines here: (12 & 13)

 

10        $PathQuery = "SELECT * FROM "+FORUM_NAME_TABLE+" WHERE forum_id='"+$forumId+"'";
11        $PathResult = mysql_query($PathQuery, $db);
12        $CatID = mysql_result($PathResult, 0, 'cat_id');
13        $ForumTitle = mysql_result($PathResult, 0, 'forum_name');

 

Errors:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/rayth/public_html/navpath.php on line 12

 

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/rayth/public_html/navpath.php on line 13

 

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/rayth/public_html/navpath.php on line 16

You need to use the period (.) to concatenate strings not the plus sign (+).

 

~juddster

 

Last I checked + or . would join strings together.

 

 

@xyph: I would assume the only time this wouldn't work is if the query didn't go through.

This is true. You don't have to assume if you check out the manual

http://php.net/manual/en/function.mysql-query.php

Look at the 'Return Values' section.

 

If you scroll down to 'See Also' you will find a function called mysql_error(). That might help you in finding out exactly why the query didn't go through.

 

And no, only . can be used for concatenation in PHP.

http://php.net/manual/en/language.operators.string.php

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.