use of undefined constant

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
balamberas
Forum Newbie
Posts: 10
Joined: Fri Mar 06, 2009 12:36 pm

use of undefined constant

Post by balamberas »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


hi, can someone help me with this error pls. the error is Use of undefined constant in line 54. Have i not defined its on top of the script foundnum=" ";??????

Code: Select all

<?php
 
include ('connect.php');
 
error_reporting(E_ALL);
ini_set('display_errors', '1');
 
$submit = $_GET['submit'];
$search = $_GET['search'];
$x=0;
$construct='';
$foundnum=" "; 
 
if (!'submit')
 
echo "you didnt submit a keyword."; 
 
else

{
 
if (strlen($search)<=2)

echo "search term to short.";
else 
{
echo " You searched for <b>$search</b><hr size='1'>";
 
//connect to our database
 
$search_exploded = explode(" ",$search);
 
 
foreach($search_exploded as $search_each)
 
{
 
// construct query
 
$x++;
if ($x==1)
$construct .= " location LIKE '%$search_each%'"; 
else
$construct .= " OR rent LIKE '%$search_each%'";
 
}
 
// echo out construct
 
$construct = "SELECT * FROM flats WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
 
if (foundnum==0)
echo "No results found.";
else
{
echo "$foundnum result found!<p>";
 
while ($runrows = mysql_fetch_assoc($run))
 
{
 
// get data
 
$select = $runrows['type'];
$title = $runrows['title'];
$location = $runrows['location'];
 
 
echo "
 
echo $title;
echo <br>;
echo $select;
echo <br>;
echo $rent;
echo <br>;
echo $location";
 
} 
 
 
}
}
}
 
 
?>

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: use of undefined constant

Post by pickle »

You're missing the $ - that's why PHP thinks it's a constant & not a variable.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
balamberas
Forum Newbie
Posts: 10
Joined: Fri Mar 06, 2009 12:36 pm

Re: use of undefined constant

Post by balamberas »

hi, thanks, that was it. do u know how to make the script search for more than just one thing? i.e £600 wood green.

$x++;
if ($x==1)
$construct .= " location LIKE '%$search_each%'";
else
$construct .= " OR location LIKE '%$search_each%'";

the way it is now. it will only search for the location and not the rent. i tried a elseif but it didnt like it nor did it work changing the OR location to rent. any ideas???
Post Reply