Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

unexpected T_IS_EQUAL, expecting T_VARIABLE or '$'

Codes here !

Moderators: macek, egami, gesf

unexpected T_IS_EQUAL, expecting T_VARIABLE or '$'

Postby QueenBea » Sun Apr 29, 2012 5:19 am

Hello

I get error

Parse error: syntax error, unexpected T_IS_EQUAL, expecting T_VARIABLE or '$' - line 22

I can't see where i have gone wrong

thanks



<html>
<head>
</head>
<body>

<centre>
<h1 style = color:#09r; font-size:36px;">Search</h1>
<form action = "./results.php" method "GET">
<input type = "text" name = "input" size="50" <?php echo $GET ["input"];?>
<input type = "submit" value = "search" />
</form>
</centre>

<?php
$input = $_GET ("input");
$terms = explode(" ",$input);
$query = "SELECT * FROM search";

foreach ($terms as $each) {
$i++;
if ($==1)
$query.="keywords LIKE '%each%' ";
else
$query.= "OR keywords LIKE '%each%' ";
}

//connect to database
mysql_connect ("localhost", " "," ");
mysql_select_db ("test");

$query = mysql_query($query);
$numrows = mysql_num_rows ($query);

if ($numrows >0) {
while ($row = mysql_fetch_assoc($query)) {
$title = $row ['title'];
echo "<h2>$title</h2>";
}

}

else
echo "No results found for \"<b>$input</b>\"";

//disconnect from database
mysql_close();

</body>
</html>
QueenBea
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Apr 18, 2012 1:50 am

Re: unexpected T_IS_EQUAL, expecting T_VARIABLE or '$'

Postby minimihi » Sun Apr 29, 2012 9:32 am

'each' in query should be variable, not a string
Also, you're missing WHERE statement in your query
User avatar
minimihi
New php-forum User
New php-forum User
 
Posts: 238
Joined: Sat Apr 14, 2012 11:57 am
Location: Vilnius, Lithuania

Re: unexpected T_IS_EQUAL, expecting T_VARIABLE or '$'

Postby QueenBea » Sun Apr 29, 2012 12:34 pm

Hi

Its still not working, have i made the correct changes?

Thanks

<html>
<head>
</head>
<body>

<centre>
<h1 style = color:#09r; font-size:36px;">Search</h1>
<form action = "./results.php" method "GET">
<input type = "text" name = "input" size="50" <?php echo $GET ["input"];?>
<input type = "submit" value = "search" />
</form>
</centre>

<?php
$input = $_GET ("input");
$terms = explode(" ",$input);
$query = "SELECT * FROM search WHERE ";

foreach ($terms as $each) {
$i++;
if ($==1)
$query.="keywords LIKE '%$each%' ";
else
$query.= "OR keywords LIKE '%$each%' ";
}

//connect to database
mysql_connect ("localhost", " "," ");
mysql_select_db ("test");

$query = mysql_query($query);
$numrows = mysql_num_rows ($query);

if ($numrows >0) {
while ($row = mysql_fetch_assoc($query)) {
$title = $row ['title'];
echo "<h2>$title</h2>";
}

}

else
echo "No results found for \"<b>$input</b>\"";

//disconnect from database
mysql_close();

</body>
</html>
QueenBea
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Apr 18, 2012 1:50 am

Re: unexpected T_IS_EQUAL, expecting T_VARIABLE or '$'

Postby minimihi » Sun Apr 29, 2012 1:42 pm

And why the hell I missed that
Code: Select all
$input = $_GET ("input"); 

Variable $_GET is array. So it should be
Code: Select all
$input = $_GET ["input"]; 


also
Code: Select all
if ($==1) 
see what are you comparing here
User avatar
minimihi
New php-forum User
New php-forum User
 
Posts: 238
Joined: Sat Apr 14, 2012 11:57 am
Location: Vilnius, Lithuania


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.