0

I have been working on a Login/Register System, I had it all set up and working perfectly in MySQL, but I need to run it from SQL SERVER 2008, so I have changed the connection over and its all working apart from 1 bit, when the user click a verification link i the email it isn't verifying the user so I am thinking that some of the syntax doesn't work with PHP7 and SQL server.

This is the code:

$stmt = $user->runQuery("SELECT userID,userStatus FROM tbl_users WHERE userID=:uID AND tokenCode=:code LIMIT 1");
$stmt->execute(array(":uID"=>$id,":code"=>$code));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0){
some code...}
else{ error message...}

Its skipping the if statement and just giving me the error message from the else.

Is there something obviously wrong that i am not seeing?

Any help would be appreciated at this point!!

Thanks.

EDIT:

This is the code form the IF statement if it helps...

if($row['userStatus']==$statusN)
    {
        $stmt = $user->runQuery("UPDATE po_users SET userStatus=:status WHERE userID=:uID");
        $stmt->bindparam(":status",$statusY);
        $stmt->bindparam(":uID",$id);
        $stmt->execute();   

        $msg = "
               <div class='alert alert-success'>
               <button class='close' data-dismiss='alert'>&times;</button>
                  <strong>WoW !</strong>  Your Account is Now Activated : <a href='index.php'>Login here</a>
               </div>
               ";   
    }
    else
    {
        $msg = "
               <div class='alert alert-error'>
               <button class='close' data-dismiss='alert'>&times;</button>
                  <strong>sorry !</strong>  Your Account is allready Activated : <a href='index.php'>Login here</a>
               </div>
               ";
    }
7
  • 1
    What you obviously not see is a manual for rowCount Commented Nov 4, 2016 at 15:08
  • 3
    SQL SERVER does not have LIMIT, use SELECT TOP instead Commented Nov 4, 2016 at 15:09
  • Since you fetched, just count($row) maybe. Commented Nov 4, 2016 at 15:10
  • Tried SELECT TOP Vitalii, still not working :( Commented Nov 4, 2016 at 15:12
  • Can you please show us what SQL error do you have? Commented Nov 4, 2016 at 15:13

3 Answers 3

1

SQl Server does not have LIMIT. Limit use with mysql. Instead of Limit use top.

Refer:http://www.w3schools.com/sql/sql_top.asp

SELECT TOP 1 userID,userStatus FROM tbl_users WHERE userID=:uID AND tokenCode=:code
Sign up to request clarification or add additional context in comments.

Comments

0

You need the TOP 1. You may be missing the 1.

SELECT TOP 1 userID, userStatus 
FROM tbl_users 
WHERE userID=:uID AND tokenCode=:code

Comments

0

So this error says that you try to call a member function on a boolean value

PHP Fatal error: Uncaught Error: Call to a member function sqlsrv_num_rows() on boolean

So instead of :

$stmt->execute(array(":uID"=>$id,":code"=>$code));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0){...

try this:

$result = $stmt->execute(array(":uID"=>$id,":code"=>$code));
if($result->rowCount() > 0){
$row = $stmt->fetch(PDO::FETCH_ASSOC);

Hope this helps!

2 Comments

Thanks for the help but after I made the changes you suggested, i get a new error before i get the same boolean error: [Mon Nov 07 08:37:13.165015 2016] [:error] [pid 2884:tid 968] [client 10.11.1.78:52544] PHP Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\\Apache24\\htdocs\\Login\\signup.php on line 21, referer: 10.11.1.224/Login/signup.php
This is the line its complaining about: if($result->rowCount() > 0){

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.