Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

This is php code:

<?php
include_once('connection.php');

class user{
    private $db;

    public function__construct(){
    $this->db = new Connection();
    $this->db = $this->db->dbConnect();
    }

    public function Login($user,$pass) {

    if(!empty($user) && !empty($pass)){
        $st = $this->db->prepare("select * from users where name=? and pass=?");
        $st->bindParam(1,$name);
        $st->bindParam(2,$pass);
        $st->execute();
        if($st->rowCount()==1){
            echo "user verified, access granted";
        }else{
            echo "incorrect username and password";
        }


    }else{
    echo "please enter username and password";
    }

    }

}
?>

In line7, it shows Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE.

Can anyone tell me how to fix this?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

use a space on function keyword and name on declaring functions so change

public function__construct(){

to

public function __construct(){

For more :- http://php.net/manual/en/language.functions.php

Also change $st->excute(); to $st->execute();

share|improve this answer
    
check my updated answer also don't forget to accept helpful answer – Rakesh Sharma Jul 18 '14 at 7:03
    
it must be execute() i think you have typo error – Rakesh Sharma Jul 18 '14 at 7:10
    
yes, correct. but when i entered input values, it shows incorrect username and password, may i know why? – selva Jul 18 '14 at 7:17
    
try if ($st->fetchColumn() > 0) { – Rakesh Sharma Jul 18 '14 at 7:20
    
i replaced with if($st->rowCount()==1){ to your answer. no change. – selva Jul 18 '14 at 7:26
- public function__construct(){
+ public function __construct(){

You have to specify “function” keyword when declaring functions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.