Jump to content

Use of undefined constant


sogorman

Recommended Posts

I am having a problem with some php code that runs on a landing page that queries a database for the content needed to display on the template page from the keywords passed in the url. My issue is that when I tried to add some php code to the template page it reads it fails and returns

 

Notice: Use of undefined constant tdbd_name - assumed 'tdbd_name' in /var/www/ppcindex.php on line 147 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /var/www/ppcindex.php on line 150

 

If anyone could point me in the right direction it would be much appreciated.

 

Here is the code from the landing page php

 

 



<?php 
// template variables - PLEASE CHANGE 


error_reporting(E_ALL); 
ini_set('display_errors','On'); 
define("TEMPLATE_NAME","ppcindexcontent.php"); // your page templates 
define("FULL_PATH","/var/www/speedppc/"); // true path to your speedPPC install directory 
define("MAX_ROWS",1); // maximum display rows for CSV data - we recommend no more the 100 records 

if(!isset($_GET["CSVID"])){ 
    define("CSVID", "18"); // CSVID of your csv file. leave blank if passing csvid in the url (See README.txt) 
} 
else { 
    define("CSVID", $_GET[csvid], true); 
} 

define("REPLACECHAR", '-'); // this is the replacement character for the custom function replace() 
// include files 
include(FULL_PATH."config.php"); 
include(FULL_PATH."common.php"); 

// variables passed in URL 
$csvkeyword = $_GET['csvkeyword']; 
$seed = $_GET['seed']; 
$expansion = $_GET['expansion']; 
$final = $_GET['final']; 

// connect to DB 
$dbhandle = dbconnect($host, $user, $pass, $db); 


// functions 
function replaceTokens($passedContent) { 
    global $csvkeyword, $seed, $expansion, $final; 
    $tokens = array("[%csvkeyword%]", "[%seed%]", "[%expansion%]", "[%final%]", "[%Csvkeyword%]", "[%Seed%]", "[%Expansion%]", "[%Final%]"); 
    $tokenValues = array(rs($csvkeyword), rs($seed), rs($expansion), rs($final), uc(rs($csvkeyword)), uc(rs($seed)), uc(rs($expansion)), uc(rs($final))); 
    $replacedContent = str_replace($tokens, $tokenValues, $passedContent); 
    return $replacedContent; 
} 

function stripUndefinedTokens($passedContent) { 
    $patterns = '/\[%.*?(%\]|\]|%)/'; 
    $result = preg_replace($patterns, '', $passedContent); 
    return $result; 
} 

function changeCase($passedContent) { 
    $patterns = '/\$.*?\]/'; 
    $string = $passedContent; 
    preg_match_all($patterns, $string, $matches); 
    $uniqueMatches = array_unique($matches[0]);   

    foreach($uniqueMatches as $key => $value) { 
        if(substr($value, 13, 1) == strtoupper(substr($value, 13, 1))) { 
            $string = str_replace($value, '".ucwords('.strtolower($value).')."', $string); 
        } 
    } 
    return $string; 
} 

function replaceChar($passedContent) { 
    $string = $passedContent; 
    $patterns = '/replace\(.*?\)/'; 
    preg_match_all($patterns, $string, $matches); 
    $replaceChar = '-'; 
    foreach($matches[0] as $key => $value) { 
        $valueReplaced = str_replace(' ', REPLACECHAR, $value); 
        $string = str_replace($value, $valueReplaced, $string); 
    } 
    $replace = array("replace(", ")"); 
    //$string = str_replace($replace, '', $string); 
    return $string; 
} 

function rs($passWord) { 
    return str_replace('-', ' ', $passWord); 
} 

function uc($passWord) { 
    return ucfirst($passWord); 
} 

// get CSV table Information 
$sql = "SELECT * FROM tabledb_details WHERE tdbd_id = '".CSVID."'"; 
$result = mysql_query($sql); 
$row = mysql_fetch_assoc($result); 

// replace '-' in keyword with space and also use keyword with '-' in it incase it is part of the word 
$keywordsArray = explode(",", $csvkeyword); 
$i = 0; 
foreach($keywordsArray as $key => $value) { 
    $keywords[$i] = $value; 
    $i++; 
    $position = strpos($value, '-'); 
    if($position !== false){ 
        $keywords[$i] = str_replace("-", " ", $value); 
        $i++; 
    } 
} 

// CSV fields  to search keyword occurence in 
$keywordFields = explode("|", $row[tdbd_search_fields]); 

$sqlKeyword = ' ('; 
foreach($keywords as $key => $value) { 
    $sqlKeyword .= "("; 
    foreach($keywordFields as $keyField => $valueField) { 
        $sqlKeyword .= "`" . $valueField . "` REGEXP '( |^)".$value."( |s|[\.]|$)' OR ";  
    } 
    $sqlKeyword = substr($sqlKeyword, 0, -4); 
    $sqlKeyword .= ") OR "; 
} 
$sqlKeyword = substr($sqlKeyword, 0, -4).')'; 

// set the default sql 'where' section if the keyword is not defined in url 
if($csvkeyword == '' || !isset($csvkeyword)) { 
    $sqlKeyword = '1'; 
} 




// start template Display Output 
ob_start(); 
include(TEMPLATE_NAME); 
$output = ob_get_contents(); 
ob_end_clean(); 

// get the position of the loop template 
$loopStart = strpos($output,"[start_csv_loop]"); 
$loopEnd = strpos($output,"[end_csv_loop]"); 
// get the loop template layout 
$loopTemplate = substr($output, ($loopStart+16), ($loopEnd-($loopStart+16))); 

// get content before loop template 
$preContent = stripslashes(stripUndefinedTokens(addslashes(replaceTokens(substr($output, 0, $loopStart))))); 

// get content after loop template 
$postContent = stripslashes(stripUndefinedTokens(addslashes(replaceTokens(substr($output, $loopEnd+14))))); 



// output pre content 
eval("\$preContent = \"$preContent\";"); 
print_r( replaceChar($preContent) ); 

$sqlSearch = "SELECT * FROM ".$row[tdbd_name]." WHERE ".$sqlKeyword." LIMIT ".MAX_ROWS; 
$resultSearch = mysql_query($sqlSearch); 

while($displayrows = mysql_fetch_assoc($resultSearch)) { 
    $display = replaceTokens($loopTemplate); 
    $display = str_replace('\\', '[backslash]', $display); 
    $display = str_replace('[%', '$displayrows[', $display); 
    $display = addslashes(str_replace('%]', ']', $display)); 
    $display = replaceTokens($display); 
    $display = changeCase($display); 

    eval("\$display = \"$display\";"); 

    $display = stripslashes($display); 
    $display = str_replace('[backslash]', '\\', $display); 
    $display = replaceChar($display); 

    print_r( $display ); 

} 
// output post content 
eval("\$postContent = \"$postContent\";"); 
print_r( replaceChar($postContent) ); 
?>

 

 

And here is part of the template (ppcindexcontent.php) the above code is reading.

                 <div style=" float:right; width: 300px; height: 0px; margin-top:-20px ; margin-bottom:0px"> 
                <p style=" font-size:16px; text-align: center;  line-height:1; color:#0391D1;">     

                 
<?php 
error_reporting(E_ALL); 
ini_set('display_errors','On'); 
$mySQLServer = "xxxxxx"; 
$mySQLUser = "xxxxxxxx"; 
$mySQLPass = "xxxxxxxxx"; 
$mySQLDB = "xxxxxxxxxxx";  
$SQLToday = date("m/d/y") . "<br />"; 
$SQLsevendays = mktime(0,0,0,date("n"),date("j")-7,date("Y")); 
$SQLsevenname = (date("l", $SQLsevendays)); 
$SQLsevennumber = (date("jS", $SQLsevendays)); 
$dbhandle = mssql_connect($mySQLServer, $mySQLUser, $mySQLPass) 
  or die("Couldn't connect to SQL Server on $myServer");  
$selected = mssql_select_db($mySQLDB, $dbhandle) 
  or die("Couldn't open database $myDB");  
$query = "WEB_ApproveHistory @State='CA', @Days=5, @Records=8"; 
$data = mssql_query($query); 
$result = array(); 

while ($row = mssql_fetch_object($data)) : 
$result[] = $row; 
$returnedresults = (97*($row->TotalApprovals)) ; 
  

endwhile; 
$englishreturnedresults = number_format($returnedresults); 
echo 'In just the last week since ' . $SQLsevenname . ' the ' . $SQLsevennumber . ' xx '; 
echo $englishreturnedresults;  
echo ' to People Just Like you In California. <br><br>Here are just a few people who' ; 

echo '<ul class="BulletCheck">'; 

mssql_next_result($data); 


while ($row = mssql_fetch_object($data)) : 

       $result[] = $row; 
       echo '<li>' . '  ' . $row->FirstName  . ' From '. $row->City . ', ' . $row->State .' PreApproved On ' .$row->ApprovedDate . '</li>'; 
endwhile; 
mssql_close($dbhandle); 
?>             

</div>

 

 

Link to comment
Share on other sites

When you get that error it means that the previous query had a syntax error and did not work. Change

<?php
$sqlSearch = "SELECT * FROM ".$row['tdbd_name']." WHERE ".$sqlKeyword." LIMIT ".MAX_ROWS; 
$resultSearch = mysql_query($sqlSearch); 
?>

to

<?php
$sqlSearch = "SELECT * FROM {$row['tdbd_name']} WHERE $sqlKeyword LIMIT ".MAX_ROWS; 
$resultSearch = mysql_query($sqlSearch) or die("Problem with the query: $sqlSearch<br>" . mysql_error());
?>

and see what is displayed. It should give you a hint as to what is wrong.

 

Ken

Link to comment
Share on other sites

Thanks kenrbnsn and all for your help with this. I'm new at this but with all your suggestions I'm picking it up. I appreciate it.

 

kenrbnsn, I swapped out the code and the page renders out without error until I try and add the SQL query to the template page and then it errors out with..

 

 

Problem with the query: SELECT * FROM WHERE ((`finalurl` REGEXP '( |^)sun-city-mortgage-rates( |s|[\.]|$)') OR (`finalurl` REGEXP '( |^)sun city mortgage rates( |s|[\.]|$)')) LIMIT 1

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ((`finalurl` REGEXP '( |^)sun-city-mortgage-rates( |s|[\.]|$)') OR (`fina' at line 1

 

I don't know if this makes any sense but it looks like the loop that scans through the template page is causing it to error out. Is it possible to have the SQL query loop inside the template page while the landing php code is looping through that?

 

Thanks again, this is starting to irk me.

Link to comment
Share on other sites

$row['tdbd_name'] has no value, and is causing the query to fail. Notice the query string says, "SELECT * FROM WHERE". There should be a value between FROM and WHERE. You should also be getting an error/warning to that effect as well, if you have error reporting on, which you should.

Link to comment
Share on other sites

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.