By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

unexpected T_IF error

P: n/a
ok, I am totally new to php and come from an asp background.

I basically want to do an If > then > else > end if statement:
my page is:

<?php require_once('Connections/carresa.php'); ?>
<?php
$DateTime = date("Y/n/j");
$IP = $_SERVER["REMOTE_ADDR"];

mysql_select_db($database_carresa, $carresa);
$query_rs = "SELECT count(Hit_DateTime) as mycount FROM unique_ip WHERE
Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
$rs = mysql_query($query_rs, $carresa) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
print "<span class=white11>" . $query_rs . "<br>IP: " .
$_SERVER["REMOTE_ADDR"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
$row_rs['mycount'] . "</span>"
//at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
THE PAGE
if ($row_rs['mycount']=='0'){
print "welcome";
}
?>
The page errors on line 17 which is the if line.

Any ideas ???

thanks
James Campbell
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"James Campbell" <ja***@stuttersystems.com> wrote:

print "<span class=white11>" . $query_rs . "<br>IP: " .
$_SERVER["REMOTE_ADDR"] . "<br>Date Time: " . $DateTime . "<br>Count:
" . $row_rs['mycount'] . "</span>"
//at this point I want to say IF row_rs['mycount']== 0 THEN PRINT
WELCOME ON THE PAGE
if ($row_rs['mycount']=='0'){
print "welcome";
}
?>
The page errors on line 17 which is the if line.


You missed a semicolon in the "print" line before the if statement.

JOn
Jul 17 '05 #2

P: n/a
I noticed that Message-ID: <Xn**************************@130.133.1.4>
from Jon Kraft contained the following:
if ($row_rs['mycount']=='0'){
print "welcome";
}
?>
The page errors on line 17 which is the if line.


You missed a semicolon in the "print" line before the if statement.

Does it matter that the '0' is in single quotes?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3

P: n/a
Geoff Berrow <bl******@ckdog.co.uk> wrote:
I noticed that Message-ID: <Xn**************************@130.133.1.4>
from Jon Kraft contained the following:
if ($row_rs['mycount']=='0'){
print "welcome";
}
?>
The page errors on line 17 which is the if line.
You missed a semicolon in the "print" line before the if statement.

Does it matter that the '0' is in single quotes?


Not really, it wouldn't throw an error for once and PHP's internal type
conversion would render that statement true if the number of rows returned
would be 0.
However, if ($row_rs['mycount']===0) would be the better solution.

JOn
Jul 17 '05 #4

P: n/a
Geoff, Jon,

Thanks for replying, I have tried both your suggestions, but still get the
error. My current code is:

if ($row_rs['mycount']===0){
print "welcome"
}

If I however put the code in like this:

<?php if ($row_rs['icount']=="0"){ ?>
<br>ddddd
<?php } ?>

The page works.

Any ideas ??

Thanks

James

"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:Xn**************************@130.133.1.4...
Geoff Berrow <bl******@ckdog.co.uk> wrote:
I noticed that Message-ID: <Xn**************************@130.133.1.4>
from Jon Kraft contained the following:
if ($row_rs['mycount']=='0'){
print "welcome";
}
?>
The page errors on line 17 which is the if line.

You missed a semicolon in the "print" line before the if statement.

Does it matter that the '0' is in single quotes?


Not really, it wouldn't throw an error for once and PHP's internal type
conversion would render that statement true if the number of rows returned
would be 0.
However, if ($row_rs['mycount']===0) would be the better solution.

JOn

Jul 17 '05 #5

P: n/a
"James Campbell" <ja***@stuttersystems.com> wrote:
Thanks for replying, I have tried both your suggestions, but still get
the error. My current code is:

if ($row_rs['mycount']===0){
print "welcome"
}

If I however put the code in like this:

<?php if ($row_rs['icount']=="0"){ ?>
<br>ddddd
<?php } ?>

The page works.

Any ideas ??


Hi James,

That doesn't make sense ... but you are using two different keys in your
example: 'mycount' and 'icount'. Could you post the complete code again?

JOn
Jul 17 '05 #6

P: n/a
I noticed that Message-ID:
<oQ******************@news-binary.blueyonder.co.uk> from James Campbell
contained the following:
if ($row_rs['mycount']===0){
print "welcome"
}


Have you tried
print "welcome";

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #7

P: n/a
Jon,

Sorry yes I saw that a few minutes ago (doh!)

The code that doesn't work is:

<?php require_once('Connections/carresa.php'); ?>
<?php
$DateTime = date("Y/n/j");
$IP = $_SERVER["REMOTE_ADDR"];

mysql_select_db($database_carresa, $carresa);
$query_rs = "SELECT count(Hit_DateTime) as mycount FROM unique_ip WHERE
Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
$rs = mysql_query($query_rs, $carresa) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
print "<span class=white11>" . $query_rs . "<br>IP: " .
$_SERVER["REMOTE_ADDR"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
$row_rs['mycount'] . "</span>"
//at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
THE PAGE
if ($row_rs['mycount']===0){
print "welcome"
}
?>

The code that does work is:

<?php require_once('Connections/carresa.php'); ?>
<?php
$DateTime = date("Y/n/j");
$IP = $_SERVER["REMOTE_ADDR"];

mysql_select_db($database_carresa, $carresa);
$query_rs = "SELECT count(Hit_DateTime) as mycount FROM unique_ip WHERE
Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
$rs = mysql_query($query_rs, $carresa) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
print "<span class=white11>" . $query_rs . "<br>IP: " .
$_SERVER["REMOTE_ADDR"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
$row_rs['mycount'] . "</span>"
//at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
THE PAGE
//if ($row_rs['mycount']===0){
//print "welcome"
//}
?>

<?php if ($row_rs['mycount']=="0"){ ?>
<br>ddddd
<?php } ?>
Seems strange how I can't include the bottom bit of code in the main chunk
of code ??

Cheers
James




"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:Xn**************************@130.133.1.4...
"James Campbell" <ja***@stuttersystems.com> wrote:
Thanks for replying, I have tried both your suggestions, but still get
the error. My current code is:

if ($row_rs['mycount']===0){
print "welcome"
}

If I however put the code in like this:

<?php if ($row_rs['icount']=="0"){ ?>
<br>ddddd
<?php } ?>

The page works.

Any ideas ??


Hi James,

That doesn't make sense ... but you are using two different keys in your
example: 'mycount' and 'icount'. Could you post the complete code again?

JOn

Jul 17 '05 #8

P: n/a
"James Campbell" <ja***@stuttersystems.com> wrote:
Jon,

Sorry yes I saw that a few minutes ago (doh!)

The code that doesn't work is:

<?php require_once('Connections/carresa.php'); ?>
<?php
$DateTime = date("Y/n/j");
$IP = $_SERVER["REMOTE_ADDR"];

mysql_select_db($database_carresa, $carresa);
$query_rs = "SELECT count(Hit_DateTime) as mycount FROM unique_ip
WHERE Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
$rs = mysql_query($query_rs, $carresa) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
print "<span class=white11>" . $query_rs . "<br>IP: " .
$_SERVER["REMOTE_ADDR"] . "<br>Date Time: " . $DateTime . "<br>Count:
" . $row_rs['mycount'] . "</span>"


Hi James,

Did you read my first post? :)

You missed a semicolon to end the above line!

JOn
Jul 17 '05 #9

P: n/a
Jon,

You are the man !!!!!

Excellent, thank you !

If you ever need and ASP code, just drop me an email.

Regards
James

"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:Xn**************************@130.133.1.4...
"James Campbell" <ja***@stuttersystems.com> wrote:
Jon,

Sorry yes I saw that a few minutes ago (doh!)

The code that doesn't work is:

<?php require_once('Connections/carresa.php'); ?>
<?php
$DateTime = date("Y/n/j");
$IP = $_SERVER["REMOTE_ADDR"];

mysql_select_db($database_carresa, $carresa);
$query_rs = "SELECT count(Hit_DateTime) as mycount FROM unique_ip
WHERE Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
$rs = mysql_query($query_rs, $carresa) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
print "<span class=white11>" . $query_rs . "<br>IP: " .
$_SERVER["REMOTE_ADDR"] . "<br>Date Time: " . $DateTime . "<br>Count:
" . $row_rs['mycount'] . "</span>"


Hi James,

Did you read my first post? :)

You missed a semicolon to end the above line!

JOn

Jul 17 '05 #10

P: n/a
James Campbell wrote:

ok, I am totally new to php and come from an asp background.

I basically want to do an If > then > else > end if statement:

my page is:

<?php require_once('Connections/carresa.php'); ?>
<?php
$DateTime = date("Y/n/j");
$IP = $_SERVER["REMOTE_ADDR"];

mysql_select_db($database_carresa, $carresa);
$query_rs = "SELECT count(Hit_DateTime) as mycount FROM unique_ip WHERE
Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
$rs = mysql_query($query_rs, $carresa) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);

print "<span class=white11>" . $query_rs . "<br>IP: " .
$_SERVER["REMOTE_ADDR"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
$row_rs['mycount'] . "</span>"

//at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
THE PAGE
if ($row_rs['mycount']=='0'){
print "welcome";
}
?>

The page errors on line 17 which is the if line.


Often, the error will be on the line prior to the one PHP reports. You didn't
end your print statement with a ";". The T_IF is unexpected because it
shouldn't be in the middle of a print statment.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.