Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problem with functions?
Old 05-01-2005, 10:06 PM Problem with functions?
Sokara's Avatar
Novice Talker

Posts: 5
Trades: 0
I'm starting to learn about sessions, and I copied to following script from a book. But I keep getting the following error:

Parse error: syntax error, unexpected T_FUNCTION in C:\Apache2\Apache2\htdocs\session.php on line 16

Any help? (Line 16 is where I define the first function. However, if I delete that function I get the same error for the next function - so it seems to be functions in general.)

PHP Code:
<? php

/*
* mysql_session_open()
*/

function mysql_session_open($session_path$session_name) {
 
mysql_pconnect("localhost")
  or die (
"Can't connect to MySQL server. ");
 
mysql_select_db("sessions")
  or die (
"Can't select MySQL database. ");
//end mysql_session_open()

/*
* mysql_session_close()
*/

function mysql_session_close() {
 return 
1;
//end mysel_session_close()

/*
* mysql_session_select()
*/

function mysql_session_select($SID) {
 
$query "SELECT value FROM sessioninfo WHERE SID = '$SID' AND expiration > "time();
 
$result mysql_query($query);
 if (
mysql_num_rows($result)) {
  
$row=mysql_fetch_assoc($result);
  
$value $row['value'];
  return 
$value;
 } else {
  return 
"";
 }
//end mysql_session_select()

/*
* mysql_session_write()
*/

function mysql_session_write($SID$value) {
 
$lifetime get_cfg_var("session.gc.maxlifetime");
 
$expiration time() + $lifetime;
 
$query "INSERT INTO sessioninfo VALUES('$SID', '$expiration', '$value')";
 
$result mysql_query($query);
 if (! 
$result) {
  
$query "UPDATE sessioninfo SET expiration = '$expiration' value = '$value' WHERE SID = '$SID' AND expiration > "time();
  
$result mysql_query($query);
 }
//end mysql_session_write()

/*
* mysql_session_destroy()
*/

function mysql_session_destroy($SID) {
 
$query "DELETE FROM sessioninfo WHERE SID = '$SID'";
 
$result mysql_query($query);
// end mysql_session_destroy()

/*
* mysql_session_garbage_collect()
*/

function mysql_session_garbage_collect($lifetime) {
 
$query "DELETE FROM sessioninfo WHERE sess_expiration < ".time() - $lifetime;
 
$result mysql_query($query);
 return 
mysql_affected_rows($result)
//end mysql_session_garbage_collect()

?>
Sokara is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-02-2005, 05:31 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
You've got two error's (probably cause of the copying from a book)

Firstyly, the <?php tag should not have a space between the <? and php

Also, at the end of the script on your last function, return mysql_affected_rows($result) should have a semicolon after the last bracket.

And that's it! Errors don't always seem to be what they really are!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 05-02-2005, 07:53 AM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Little hint. When dealing with parse errors, always look above the line the error say's it's on.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 05-02-2005, 09:49 AM
Sokara's Avatar
Novice Talker

Posts: 5
Trades: 0
Ah, I hate stupid mistakes. Thanks so much you guys
Sokara is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem with functions?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.14896 seconds with 12 queries