开发者

PHP class and javascript

i am working on PHP login form. I must use a class:

  <?php
    class loginController_ extends Controller_
    {
        public $loginok;
    // Session
    session_start();


    mysql_connect("localhost", "root", "") or die(开发者_运维知识库);
    mysql_select_db("db") or die();

    // pobranie danych:
    $user = $_POST['us'];
    $pawss = $_POST['pwd'];     

    $login = mysql_query("SELECT * FROM users WHERE user ='$user'");
    $row = mysql_fetch_assoc($login);

    $dbpass = $row['pass'];
    $dbuser = $row['user'];

    if ($pass==$dbpass && $user==$dbuser)
    {
        $loginok = TRUE;


        $_SESSION['user']=$user;
        }
    else
    {   
        $loginok = FALSE;

    }

    }

    if ($loginok==TRUE)
    {
    echo 'yes';
    }

    else 
    {
    echo 'no';
    }
    ?>

I have declared variable "loginok" as public, because, I'd like to return value of this php file (echo 'yes';/ echo 'no') to my script, which checks being of user. Unfortunatelly id does not work. How to hand over value of "loginok" out of the class?


The view that calls this controller needs to access that variable and then pass it to the JS.

There's no way your code would work right now as all that code needs to go inside a method in the loginController_ class. Call that method, and have it return the result.

Once you have that result, you need to give it to the view. If you mix PHP and HTML you can simply do this

<script>
   var loginStatus = "<?php echo $loginStatus ?>"
</script>

If you're using a framework, you can usually do something like $this->view->loginStatus = $loginStatus;. Can't give you a concrete answer until you tell us what framework you're using. In any case, your PHP class is broke.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜