Welcome to WebmasterWorld Guest from 23.22.220.37

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Parse error - trim function

     
9:33 pm on Jun 1, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 1, 2004
posts:389
votes: 0


Hi guys,

I cant work out what I have done wrong?

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$'

PHP Code:
// Check for a database name
if(empty(trim($db)){
$errors = 'Please enter the name of your database.';
}

Can anyone help?

10:06 pm on June 1, 2007 (gmt 0)

Preferred Member

5+ Year Member

joined:Feb 11, 2006
posts:481
votes: 0


Hi,

The empty function is special because it can only accept a variable as an argument, you need to do:


$temp = trim($db);
if(empty($temp)){

or

if(strlen(trim($db)) == 0){

Andrew

[edited by: Little_G at 10:25 pm (utc) on June 1, 2007]

10:09 pm on June 1, 2007 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts:4388
votes: 2


If $db is empty why would you trim it?
10:10 pm on June 1, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 22, 2005
posts:152
votes: 0


if(empty(trim($db)){
$errors = 'Please enter the name of your database.';
}

you left one of the closing brackets.

if(empty(trim($db))[b])[/b]{
$errors = 'Please enter the name of your database.';
}

[edited by: Mohamed at 10:11 pm (utc) on June 1, 2007]

10:23 pm on June 1, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 1, 2004
posts: 389
votes: 0


thanks for the reply guys :)

I did miss a bracket, yes...
However this is still giving same error?

[PHP]
if(empty(trim($db))){
$errors = 'Please enter the name of your database.';
} [/PHP]

5:15 am on June 2, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:May 18, 2007
posts:49
votes: 0


Hi,

This may not look good as the earliers. But I hope it will do the trick.
<?php
$test=trim($db);
if($test=="")
{
echo("Please enter the name of the Database.");
}
?>

10:44 am on June 2, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


adammc,

As previously mentioned, empty only checks vars. From the PHP website:


Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

Why not use:

if (trim($db)=='')
{
echo("Please enter the name of the Database.");
}

dc