Code: Select all
$title = '';
//then the rest part of your code.
Moderator: General Moderators
Code: Select all
$title = '';
//then the rest part of your code.
If this is the case, then why does the second script below work (using $_GET['page'])?$_GET['title'] will only be set if it exists in your URL. i.e yourpage.php?title=something
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;
?>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;
?>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;
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:If this is the case, then why does the second script below work (using $_GET['page'])?
The answer why is pretty straightforward. You have attempted to access an array where the specified key does not exist. Ummm ... lets see.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"
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'];
Upon applying the code above, I did not get an error, but nothing printed well?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;
Code: Select all
$intro_title = "SELECT title FROM introtext WHERE page='DUMMY VALUE'";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;
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=WedEnsCode: 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