Page 2 of 2

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 1:47 am
by pcoder
Set the $title variable to null before using it.

Code: Select all

 
$title = '';
//then the rest part of your code.
 

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 1:55 am
by imimin
Still getting the error:


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

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 2:07 am
by Stryks
Sorry to jump on in here ...

$_GET['title'] will only be set if it exists in your URL. i.e yourpage.php?title=something

If you set $title ... then you set $title, not $_GET['title'];

Hope that helps.

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 2:13 am
by myfriend
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 2:19 am
by imimin
Thanks guys!
$_GET['title'] will only be set if it exists in your URL. i.e yourpage.php?title=something
If this is the case, then why does the second script below work (using $_GET['page'])?

Also, could you please then tell me why I am getting the error:

"Notice: Undefined index: title in c:\program files\easyphp1-8\www\lifesannouncements\ccpageview.php on line 84"

for the code:

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;
        ?>
When the code:

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;
        ?>
works? (I am sorry for the repeated question, just wanted to give you a bottom line).

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 2:30 am
by pcoder
What kind of error did you get when using this:

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];
echo $title_text;
 

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 3:07 am
by Stryks
Try the code pcoder tried and then post back.

But to answer your questions ...
imimin wrote:If this is the case, then why does the second script below work (using $_GET['page'])?
Well ... I don't know that it DOES work. Maybe you have an entry in your database where page ='', or maybe page is being passed as a part of the URL as I described earlier.
imimin wrote:Also, could you please then tell me why I am getting the error:

"Notice: Undefined index: title in c:\program files\easyphp1-8\www\lifesannouncements\ccpageview.php on line 84"
The answer why is pretty straightforward. You have attempted to access an array where the specified key does not exist. Ummm ... lets see.

Code: Select all

$test = array('name'=>'fred', 'age'=>21);
 
//This will work
echo $test['name'];
 
// So will this
echo $test['age'];
 
// This will produce the error you are getting
echo $test['superpower'];
 
This is because 'superpower' is not a key that is set. And make no mistake, $_GET is still an array, albeit a superglobal one. It is automatically populated from parameters specified in the URL used to call the page.

MyPage.php?name=fred&age=21

The above would populate the $_GET array to the exact same content as the $test array I used above.

So, understanding that ... you answer is, "you are getting the error because you are using an undefined index. $_GET['title'] is not set.

pcoders code seeks to verify this ... and it will help us out to no end if it was validated. So could you please run the code and let us know the results.

Cheers

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 10:15 am
by imimin
pcoder wrote:What kind of error did you get when using this:

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];
echo $title_text;
 
Upon applying the code above, I did not get an error, but nothing printed well?

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 10:52 am
by imimin
A sample of my 'introtext' table from my db...

http://www.iiint.com/img/introtext%20table.pdf

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 6:45 pm
by Stryks
I imagine it didn't show anything because $_GET['title'] was not set was therefore set to 'DUMMY VALUE'. This makes your query ...

Code: Select all

$intro_title = "SELECT title FROM introtext WHERE page='DUMMY VALUE'";
You can test this with ...

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'";
echo "Query Used: -- $intro_title<br /><br />";
echo "URL Query String: -- {$_SERVER['QUERY_STRING']}<br /><br />";
$intro_title = mysql_query($intro_title);
$title_text = mysql_fetch_array($intro_title);
$title_text = $title_text[0];
echo $title_text;
 
I also added something that might help clarify things a little for me. If you can post the results, that'd be great.

Cheers

Re: HELP! Undefined index: title...

Posted: Tue Sep 16, 2008 10:03 pm
by imimin
When I click on the Wedding Invitations link, I get the following error(s):

Code: Select all

Query Used: -- SELECT title FROM introtext WHERE page='WedEns'
 
URL Query String: -- cc_link=http://free.cceasy.com/order/index.cfm?sjumptoproductline=WedEns&page=WedEns&paget=WedEns&pagekws=WedEns&title=WedEns
When I click on the Wedding Accessories link, I get the following error(s):

Code: Select all

Query Used: -- SELECT title FROM introtext WHERE page='DUMMY VALUE'
 
URL Query String: -- cc_link=http://free.cceasy.com/order/index.cfm?sjumptoproductline=Bridal&page=Bridal&paget=Bridal&pagekws=Bridal
 
THANK YOU FOR YOUR HELP!

Re: HELP! Undefined index: title...

Posted: Wed Sep 17, 2008 12:35 am
by Stryks
Well .. as you can see. The query in the first snippet has a proper value in the query, and this is because there is a 'view' parameter (among other things) in the URL.

Whereas, on the second snippet, you can see that there is no 'view' parameter in the URL, and therefore the query contains the value 'DUMMY VALUE'.

I would take it then, that whatever method you are using to assemble your URL's requires that a title be specified, and at the moment it is not.

You can remove the two echo lines from my code snippet to remove the output by the way. They aren't errors ... just notices to let us know what is going on.

If you're not sure what I'm saying, then let me put it like this. There is no title being passed in the URL of the second snippet above. Therefore $_GET['title'] is not set, hence the error. Your best bet will be to go back to where both those URL's are made (on the page before) and see why one has a title and the other does not.

Not knowing anything else about your site's inner workings, I cant really be any more specific than that.

Hope it helps anyhow.

Re: HELP! Undefined index: title...

Posted: Thu Sep 18, 2008 10:04 am
by imimin
Thank you!

I see now where in my 'links.inc' file, I never set up the 'view' parameters for all of my links, I set up everything else (including a link to a frame and meta data which are some of the other parameters you see there) EXCEPT for the 'view' parameter!