Jump to content

[SOLVED] Error with class/php file..


Recommended Posts

I'm trying to implement a class file so I don't have to duplicate a lot of code, anyways I keep getting this syntax error and I'm pulling my hair out trying to figure out why..

 

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /ActiveUser.class.php on line 5

 

Here is my ActiveUser.class.php code..

<?php
class ActiveUser
{

public function __construct()
{
}

public function count($username, $password = null, $link = null)
{
$sql = "SELECT COUNT(*) FROM active_user WHERE username = ".mysql_real_escape_string($username)."";

if (!empty($password))
{
$sql .= " AND password = ".md5($password)."";
}

$query = $this->query($sql,$link);

return mysql_result($query, 0, 0);
}

public function insert($username, $password, $link)
{
$sql = "INSERT INTO active_user VALUES (”,".$username.", ".md5($password).")";
$query = $this->query($sql, $link);
}

private function query($sql, $link)
{
$query = mysql_query($sql,$link);

if (!$query)
{
return "problem with sql, ".mysql_error();
}

else
{
return $query;
}

}
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/125324-solved-error-with-classphp-file/
Share on other sites

What version of PHP are you using? You should not be having any problems if you're using PHP5 . However you will get that error with PHP4.

 

PHP4 has very limited OOP support. PHP4 does not support visibility keywords (public, private, protected) nor does it support magic function such as __construct

Try

 

<?php
class ActiveUser
{

public function ActiveUser()
{
}

public function count($username, $password = null, $link = null)
{
$sql = "SELECT COUNT(*) FROM active_user WHERE username = ".mysql_real_escape_string($username)."";

if (!empty($password))
{
$sql .= " AND password = ".md5($password)."";
}

$query = $this->query($sql,$link);

return mysql_result($query, 0, 0);
}

public function insert($username, $password, $link)
{
$sql = "INSERT INTO active_user VALUES (”,".$username.", ".md5($password).")";
$query = $this->query($sql, $link);
}

private function query($sql, $link)
{
$query = mysql_query($sql,$link);

if (!$query)
{
return "problem with sql, ".mysql_error();
}

else
{
return $query;
}

}
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.