homepage Welcome to WebmasterWorld Guest from 23.20.220.79
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
unexpected t_variable
Php syntax error
hirerobhere




msg:3509950
 5:39 pm on Nov 20, 2007 (gmt 0)

Hello. I am having trouble with the following code. I get an unexpected t_variable on noted line. Any ideas? Thanks!

<?
if(get_magic_quotes_gpc())
$keyword=stripslashes($_GET['aff']);
else
$keyword=$_GET['aff'];
include("includes/dbconnector.php");
$query="select output from keyword where keyword='".mysql_real_escape_string($keyword)."'";
if($result=mysql_query($query,$db))
{
$var=mysql_fetch_array($result)
$output=$var['output']; //Problem is here.
echo $output;
}
else
include("includes/home.php");
?>

 

hirerobhere




msg:3509955
 5:41 pm on Nov 20, 2007 (gmt 0)

Nevermind got it.

ayushchd




msg:3509958
 5:43 pm on Nov 20, 2007 (gmt 0)

If you are fetching array, it should be :
$output=$var[0];

If you want $output=$var['output'], then you have to us mysql_fetch_assoc :
$var=mysql_fetch_assoc($result);
$output=$var['output'];

hirerobhere




msg:3510010
 6:38 pm on Nov 20, 2007 (gmt 0)

Thanks, but I seem to be having a new problem. I may be doing this wrong. I am trying to see if a value exists in a table and then if it doesn't just include a different file. But it seems as though when I use this :

<?
if(get_magic_quotes_gpc())
$keyword=stripslashes($_GET['aff']);
else
$keyword=$_GET['aff'];
include("includes/dbconnector.php");
$query="select output from keyword where keyword='".mysql_real_escape_string($keyword)."'";
if($result=mysql_query($query,$db))
{
$var=mysql_fetch_assoc($result);
$output=$var['output'];
echo $output;
}
else
include("includes/home.php");
?>

It's not getting to the else ever. It seems to echo $output even if it's null. Any ideas?

hirerobhere




msg:3510019
 6:45 pm on Nov 20, 2007 (gmt 0)

Ok I did it this way :

<?
if(get_magic_quotes_gpc())
$keyword=stripslashes($_GET['aff']);
else
$keyword=$_GET['aff'];
include("includes/dbconnector.php");
$query="select output from keyword where keyword='".mysql_real_escape_string($keyword)."'";
$result=mysql_query($query,$db);
$var=mysql_fetch_assoc($result);
$output=$var['output'];
if($output!='')
echo $output;
else
include("includes/home.php");
?>

Does this look ok?

ayushchd




msg:3510055
 7:24 pm on Nov 20, 2007 (gmt 0)

I think you should use the mysql function : mysql_num_rows()

$query="select output from keyword where keyword='".mysql_real_escape_string($keyword)."'";
$result=mysql_query($query,$db);
if (mysql_num_rows($result)!= 0) {
$var=mysql_fetch_assoc($result);
$output=$var['output'];
} else {
include("includes/home.php");
}

Oops, I missed out the underscore!
[edited by: eelixduppy at 7:25 pm (utc) on Nov. 20, 2007]

[edited by: ayushchd at 7:33 pm (utc) on Nov. 20, 2007]

kwasher




msg:3510061
 7:32 pm on Nov 20, 2007 (gmt 0)

Just a thought... sometimes var='' may appear empty to humans but isnt. Have a look at 'isset' and 'empty'.

hirerobhere




msg:3510071
 7:41 pm on Nov 20, 2007 (gmt 0)

Thanks for the replies guys... Doing some research...

hirerobhere




msg:3510078
 7:48 pm on Nov 20, 2007 (gmt 0)

I'm probably going to go with isset because the num_rows won't work in this case. I need to actually use the result content not just see if it's there. Thanks again though.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved