Page 1 of 2

HELP! Undefined index: title...

Posted: Mon Sep 15, 2008 12:56 am
by imimin
Can someone please tell me what is wrong with my code? I am getting the following error: "Notice: Undefined index: title in c:\program files\easyphp1-8\www\lifesannouncements\ccpageview.php on line 83". Following are snippets of the file named 'ccpageview.php' (full code follows at end):

Code: Select all

        $title = mysql_fetch_array($page_title);
            $title = $title[0];
            echo $title;
. . .

Code: Select all

            <?php
 
                $title = $_GET['title'];
                $intro_title = "SELECT title FROM introtext WHERE page='$title'";
                $intro_title = mysql_query($intro_title);
                $title_text = mysql_fetch_array($intro_title);
                $title_text = $title_text[0];
                echo $title_text;
        ?>
Thank you!

Full 'ccpageview.php' code:

Code: Select all

<?php
include("includes/defs.php");
include("includes/db_connect.php");
?>
<?php
include("includes/docheader.php");
?>
<HTML>
<HEAD>
<TITLE><dynamic from DB></TITLE>
 
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<meta name="keywords" content="<?php
 
            $paget = $_GET['paget'];
            $page_title = "SELECT keywords FROM metatags WHERE page='$paget'";
            $page_title = mysql_query($page_title);
            $title = mysql_fetch_array($page_title);
            $title = $title[0];
            echo $title;
        ?>">
<meta name="description" content="<?php
 
            $pagekws = $_GET['pagekws'];
            $page_keywords = "SELECT title FROM metatags WHERE page='$pagekws'";
            $page_keywords = mysql_query($page_keywords);
            $keywords = mysql_fetch_array($page_keywords);
            $keywords = $keywords[0];
            echo $keywords;
        ?>">
<!--ANY OTHER META TAGS WE SHOULD INCLUDE???-->
 
<?php include("includes/style.inc"); ?>
 
</HEAD>
 
<BODY>
 
    <!--<?php
    function page_intro_text() {
        $page = $_GET['page'];
        $intro_text = "SELECT intro_text FROM introtext WHERE page='$page'";
        $intro_text = mysql_query($intro_text);
        $text = mysql_fetch_array($intro_text);
        $text = $text[0];
        echo $text;
    }
    ?>-->
 
<?php
 
include("includes/header.inc");
 
?>
<CENTER>
 
<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="5">
<TR>
    <TD VALIGN="top">
    <?php
    include("includes/left_links.inc");
    ?>
    <BR>
        <?php
        include("includes/resources_info.inc");
    ?>
    <BR>
    <?php
    include("includes/help_links.inc");
    ?>
    </TD>
    <TD>
    &nbsp;&nbsp;
    </TD>
    <TD width="100%" ALIGN="center" VALIGN="top">
 
    <BR>
 
    <P align="center"><b>
 
            <?php
 
                $title = $_GET['title'];
                $intro_title = "SELECT title FROM introtext WHERE page='$title'";
                $intro_title = mysql_query($intro_title);
                $title_text = mysql_fetch_array($intro_title);
                $title_text = $title_text[0];
                echo $title_text;
        ?></b>
 
    <P align="left">
 
        <?php
 
            $page = $_GET['page'];
            $intro_text = "SELECT intro_text FROM introtext WHERE page='$page'";
            $intro_text = mysql_query($intro_text);
            $text = mysql_fetch_array($intro_text);
            $text = $text[0];
            echo $text;
        ?>
 
        <br>
        <br>
 
    <a href="http://localhost/lifesannouncements/noframes.php" frame="right"><blockquote><small>If you are using a browser that does not support frames or if you wish to view the preview product root of the information below in a seperate window, CLICK on this link.</small></blockquote></a>
 
    <!--<?php
    page_intro_text();
    ?>-->
 
    </P>
 
        <?php
        // syntax for linking to iframe:
        // http://localhost/lifesannouncements/ccp ... localhost/
        if(isset($_GET['cc_link'])){
            $cc_link = $_GET['cc_link'];
        }else{
            $cc_link = "about&#058;blank";
        }
        ?>
 
    <IFRAME src="<?php echo $cc_link ?>" frameborder="0" width="100%" height="1000"><center><b>NOTICE:</b></center>
 
    You have entered a section of Life's Announcements (providers of world class birth announcements, wedding invitations and graduation announcements) web site that requires frames to view properly (it appears that the web-browser you are currently using does not support frames).  This is no problem, however, as we have provided to you, our valued customer, special pages that will allow you to view the information you have requested, order any items from these pages you choose and then re-enter the normal view of our web-site after you are done with these pages.  There are a few things you should be aware of as you view this portion of our web site <b>(PLEASE READ THE FOLLOWING INFORMATION CAREFULLY)</b>:
    <OL>
    <LI>You will have to click on the “CLICK HER TO CONTINUE” link below in order to get started and view the information you requested.</LI>
    <LI>The next page will have some general information on it concerning the product category you initially selected.  Read this for some valuable information.  When you are ready to view the product line and products you are interested in, click on the sample product image or text below it to proceed; this will open a new web-browser window with product information and links to specific products contained therein.</LI>
    <LI>At this point you will be able to view products, read their descriptions and order any product(s) you desire.  When finished with your shopping needs, you can close the new web-browser window and return to our main web site.</LI>
    </OL>
    Thank you very much for your cooperation.  We are sorry for any inconvenience this may cause.  This is no fault of ours, it’s just how the Internet works - we have made it as simple for you as possible.
    <br>
    <br>
    <a href="http://localhost/lifesannouncements/noframes.php" frame="right">CLICK HERE TO CONTINUE</a>
 
    </IFRAME>
 
    </TD>
 
    <!--<TD VALIGN="top">
    <?php
    include("includes/login_box.inc");
    ?>
    </TD>-->
</TR>
 
</TABLE>
 
</CENTER>
 
<TABLE cellpadding="30">
<TR>
<TD>
 
<?php include("includes/bottom_info.php"); ?>
 
</TD>
</TR>
</TABLE>
 
<?php include ("includes/footer.inc"); ?>

Re: HELP! Undefined index: title...

Posted: Mon Sep 15, 2008 1:48 am
by Ziq
It means that you not defined a variable before. To solve this problem exist many different ways:

Code: Select all

 
<?
//...
//  Check variable
if (!empty($_GET['title'])) $title = $_GET['title'];
if (isset($_GET['title'])) $title = $_GET['title'];
//  or predefined
$title = '';
$title = $_GET['title'];
//  or change error_reporting level
//  In begin your script
error_reporting(E_ALL ~E_NOTICE);
$title = $_GET['title'];
//  or ...
$title = @$_GET['title'];
//  or ...
//...
?>
 
The notice warning isn't a danger (as a rule). Look at the manual, if you couldn't to understand this constructions.

P.S. Check the input data.

Re: HELP! Undefined index: title...

Posted: Mon Sep 15, 2008 10:00 pm
by imimin
But didn't I define the variable here:

Code: Select all

    $title = mysql_fetch_array($page_title);
              $title = $title[0]
              echo $title;
?

Thanks

Re: HELP! Undefined index: title...

Posted: Mon Sep 15, 2008 10:19 pm
by imimin
BTW...

I define $page_title previously in the following code:

Code: Select all

            $paget = $_GET['paget'];
            $page_title = "SELECT keywords FROM metatags WHERE page='$paget'";
            $page_title = mysql_query($page_title);
            $title = mysql_fetch_array($page_title);
            $title = $title[0];
            echo $title;

Re: HELP! Undefined index: title...

Posted: Mon Sep 15, 2008 11:41 pm
by imimin
I am sorry (I am fairly new to php, BUT REALLY WANT TO LEARN), but the above code:

Code: Select all

            $paget = $_GET['paget'];
            $page_title = "SELECT keywords FROM metatags WHERE page='$paget'";
            $page_title = mysql_query($page_title);
            $title = mysql_fetch_array($page_title);
            $title = $title[0];
            echo $title; 
is not associated with my problem as far as i can tell (it is associated with another part of my page!!!). If I remove this code, I still have the same problem!

As far as i can tell, the only code that is NOT working correctly is:

Code: Select all

            <?php
 
                $title = $_GET['title'];
                $intro_title = "SELECT title FROM introtext WHERE page='$title'";
                $intro_title = mysql_query($intro_title);
                $title_text = mysql_fetch_array($intro_title);
                $title_text = $title_text[0];
                echo $title_text;
 
I am getting the following error: "Notice: Undefined index: title in c:\program files\easyphp1-8\www\lifesannouncements\ccpageview.php on line 84"

What is really confusing me is a VERY simular piece of code is working correctly:

Code: Select all

        <?php
 
            $page = $_GET['page'];
            $intro_text = "SELECT intro_text FROM introtext WHERE page='$page'";
            $intro_text = mysql_query($intro_text);
            $text = mysql_fetch_array($intro_text);
            $text = $text[0];
            echo $text;
        ?>
As you can see, its pulling from the same database and same table, just a different column.

Can someone please tell me what I am doing wrong?

THANK YOU SO MUCH!

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 12:25 am
by pcoder
Usually this kind of error occurs when the variable is not property set.
Check if the get variable is set before use it.
Try this before use the get variable.

Code: Select all

 
if(isset($_GET['title']) && trim($_GET['title'])!=''){
$title = $_GET['title'];
}
 

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 12:34 am
by imimin
So, by using this code, if the $_GET is set, it will print, if it is not set it will not print also not show an error?

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 12:42 am
by pcoder
If the $_GET is not set, try to insert any dummy value and see if that error ocuurs or not.

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 12:46 am
by imimin
I inserted dummy value of $test:

Code: Select all

$title = $test['title'];
in place of

Code: Select all

$title = $_GET['title'];
and I still get the error!

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 12:57 am
by pcoder
Try this to check

Code: Select all

 
if(isset($_GET'title']) && trim($_GET['title'])!=''){
$title = $_GET['title'];
}else{
$title = 'DUMMY VALUE';
}
$intro_title = "SELECT title FROM introtext WHERE page='$title'";
$intro_title = mysql_query($intro_title);
$title_text = mysql_fetch_array($intro_title);
$title_text = $title_text[0];
 

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 1:02 am
by imimin
When I run this as listed, I get the following error:

Parse error: parse error, expecting `','' or `')'' in c:\program files\easyphp1-8\www\lifesannouncements\ccpageview.php on line 84

Line 84:

if(isset($_GET'title']) && trim($_GET['title']!='')

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 1:15 am
by pcoder
Sorry, i forgot to put the braces. Now you can use that part.

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 1:29 am
by imimin
Still giving me same error.

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 1:35 am
by pcoder
Are you getting the same error at the same place?

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 1:37 am
by imimin
yes