Reply
Strange PHP error (parse error)
Old 01-01-2009, 04:17 PM Strange PHP error (parse error)
Novice Talker

Posts: 12
Name: Noam .
Hey guys.
I got this code:
Code:
<?php
/*--------------------------------------------------------------------
Settings File
--------------------------------------------------------------------*/
// DB Settings
define("MySQL_Server","localhost"); //MySQL Server
define("MySQL_Username","root"); //MySQL Username
define("MySQL_Password",""); //MySQL Password

define("MySQL_DB_Name","yeadim_d0b") //MySQL DB Name

/*--------------------------------------------------------------------
Global Functions
--------------------------------------------------------------------*/
function DBConnect()‎
{
$MySQL_Link = mysql_connect(MySQL_Server,MySQL_Username,MySQL_Password) or die(""); //MySQL Connection

//Connection check
if ($MySQL_Link==false) {
return false;
}
else {
if (mysql_select_db(MySQL_DB_Name,$MySQL_Link))
{return true;}
else
{return false;}
}
?>‎
The error:
Quote:
Parse error: parse error in C:\wamp\www\Yeadim\Sets.php on line 15
and the line with the error is
Quote:
function DBConnect()‎
So... what the hell?

Last edited by noam_moshe : 01-01-2009 at 04:19 PM.
noam_moshe is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 01-01-2009, 04:56 PM Re: Strange PHP error (parse error)
Decaf's Avatar
Ultra Talker

Posts: 490
Name: Adam
did you pass in your arguments?
__________________
Decaf is online now
Reply With Quote
View Public Profile Visit Decaf's homepage!
 
Old 01-01-2009, 05:04 PM Re: Strange PHP error (parse error)
chrishirst's Avatar
Super Moderator

Posts: 19,022
Location: Blackpool. UK
Just the usual errant semi-colon

define("MySQL_DB_Name","yeadim_d0b"); //MySQL DB Name
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-01-2009, 06:30 PM Re: Strange PHP error (parse error)
King Spam Talker

Posts: 1,362
Chris nailed it again.

The line number for the error message is frequently one less that what is displayed in the error message because the error occurs when PHP can not parse the line properly because of a missed semiclon on the line above.
colbyt is offline
Reply With Quote
View Public Profile
 
Old 01-02-2009, 03:30 AM Re: Strange PHP error (parse error)
Novice Talker

Posts: 12
Name: Noam .
Quote:
Originally Posted by chrishirst View Post
Just the usual errant semi-colon

define("MySQL_DB_Name","yeadim_d0b"); //MySQL DB Name
ha ha thanx, now I got another problem:
Code:
 Parse error:  parse error, expecting `'{'' in C:\wamp\www\Yeadim\Sets.php on line 15
the same code + the semi-colon fix.
line 15 is "function D‎BConnect()‎".

Thanks, Noam
noam_moshe is offline
Reply With Quote
View Public Profile
 
Old 01-02-2009, 03:53 AM Re: Strange PHP error (parse error)
chrishirst's Avatar
Super Moderator

Posts: 19,022
Location: Blackpool. UK
PHP Code:
<?php
/*--------------------------------------------------------------------
Settings File
--------------------------------------------------------------------*/
// DB Settings
define("MySQL_Server","localhost"); //MySQL Server
define("MySQL_Username","root"); //MySQL Username
define("MySQL_Password",""); //MySQL Password

define("MySQL_DB_Name","yeadim_d0b"); //MySQL DB Name

/*--------------------------------------------------------------------
Global Functions
--------------------------------------------------------------------*/
function DBConnect()&#8206;
{
$MySQL_Link mysql_connect(MySQL_Server,MySQL_Username,MySQL_Password) or die(""); //MySQL Connection

//Connection check
if ($MySQL_Link==false) {
return 
false;
}
else {
if (
mysql_select_db(MySQL_DB_Name,$MySQL_Link))
{return 
true;}
else
{return 
false;}
}
?>
That's a copy and paste of your code from above (with the semi-colon) notice any thing odd in line 15?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-02-2009, 04:02 AM Re: Strange PHP error (parse error)
Novice Talker

Posts: 12
Name: Noam .
now it's the first time I see it!
I wrote the file in ANSI. After turning it to utf8, the document had strange  (wtf?) in few places. I've deleted it and it works just fine.
What is it?
noam_moshe is offline
Reply With Quote
View Public Profile
 
Old 01-02-2009, 04:43 AM Re: Strange PHP error (parse error)
chrishirst's Avatar
Super Moderator

Posts: 19,022
Location: Blackpool. UK
Depends on what editor you used, some will add formatting/wordprocessor control characters.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-02-2009, 04:45 AM Re: Strange PHP error (parse error)
Novice Talker

Posts: 12
Name: Noam .
Quote:
Originally Posted by chrishirst View Post
Depends on what editor you used, some will add formatting/wordprocessor control characters.
bloody notepad...
noam_moshe is offline
Reply With Quote
View Public Profile
 
Old 01-02-2009, 04:57 AM Re: Strange PHP error (parse error)
chrishirst's Avatar
Super Moderator

Posts: 19,022
Location: Blackpool. UK
Curious, can't say I've ever seen notepad add characters.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-02-2009, 06:00 AM Re: Strange PHP error (parse error)
Novice Talker

Posts: 12
Name: Noam .
well, another problem.
I've tweaked my code a little bit (some of it was wrong as you noticed).
The problem: infinite loop. The rest of the code is fine...
BTW: the die(...) errors are in Hebrew.
The program prints 111111111111111111111... (the content of "Acid").

Code:
<?php
/*--------------------------------------------------------------------
Settings File
--------------------------------------------------------------------*/
// DB Settings
define("MySQL_Server","localhost"); //MySQL Server
define("MySQL_Username","root"); //MySQL Username
define("MySQL_Password",""); //MySQL Password

define("MySQL_DB_Name","blabla"); //MySQL DB Name

/*--------------------------------------------------------------------
Global Functions
--------------------------------------------------------------------*/

function DBConnect($Q)
{
$MySQL_Link = mysql_connect(MySQL_Server, MySQL_Username, MySQL_Password) or die("שגיאה"); //MySQL Connection
//Connection check
$MySQL_DB_Selection = mysql_select_db(MySQL_DB_Name, $MySQL_Link) or die("שגיאה 2");
//Query
$MySQL_Q=mysql_query($Q,$MySQL_Link) or die("שגיאה 3");
Global $MySQL_Row;
$MySQL_Row=mysql_fetch_array($MySQL_Q) or die("שגיאה 4");
}
DBConnect("select * from acats;");

while ($MySQL_Row)
{
echo $MySQL_Row['Acid'];

}


function DBClose()
{
mysql_close($MySQL_Link);
}
?>

Last edited by noam_moshe : 01-02-2009 at 06:02 AM.
noam_moshe is offline
Reply With Quote
View Public Profile
 
Old 01-02-2009, 06:38 AM Re: Strange PHP error (parse error)
chrishirst's Avatar
Super Moderator

Posts: 19,022
Location: Blackpool. UK
Quote:
errors are in Hebrew.
That probably explains the strange characters then

seperate the function definitions from the working codebase.

GET RID of the global variable, they are rarely a good idea, and make DBConnect return a value to the function call.

Ensure that the function DOES return false on any errors.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Strange PHP error (parse error)
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13403 seconds with 12 queries