php - querying another table after login -
this seems should simple, i've tried every way , can't seem work.
i have login script adapted online tutorial. i'd have users sign in username , password, , if these correct, have go after lab results in table (same database) , display them. can sign in, that's it. here's login code:
<?php //start session session_start(); require('connect.php'); //3. if form submitted or not. //3.1 if form submitted if (isset($_post['username']) , isset($_post['password'])){ //3.1.1 assigning posted values variables. $username = $_post['username']; $password = $_post['password']; //3.1.2 checking values existing in database or not $query = "select * `user` username='$username' , password='$password'"; $result = mysql_query($query) or die(mysql_error()); $count = mysql_num_rows($result); //3.1.2 if posted values equal database values, session created user. if ($count == 1){ $_session['username'] = $username; }else{ //3.1.3 if login credentials doesn't match, shown error message. echo "invalid login credentials."; } } //3.1.4 if user logged in greets user message if (isset($_session['username'])){ $username = $_session['username']; echo "hi " . $username . "! "; echo "this results of inquiry.<br><br>"; /*this i'm assuming new query needs go. query different table named "data" , pick out information according $username put in earlier */ echo "<br><a href='logout.php'>logout</a>"; }else{ //3.2 when user visits page first time, simple login form displayed. ?> <!doctype html> <html> <head> <title>lab sign in page</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <!-- form logging in users --> <div class="register-form"> <?php if(isset($msg) & !empty($msg)){ echo $msg; } ?> <h1>login</h1> <form action="" method="post"> <p><label>user name :</label> <input id="username" type="text" name="username" placeholder= "username"></p> <p><label>password :</label> <input id="password" type="password" name="password" placeholder="password"></p><a class="btn" href="register.php">signup</a> <input class= "btn register" type="submit" name="submit" value="login"> </form> </div><?php } ?> </body> </html>
a "join" when google doesn't seem right. help?
thanks!
you can use different query making easy:
$sql = mysql_query("select * data user = '" . mysql_real_escape_string($username) . "'");
then can process this.
please note should not use mysql driver deprecated, use mysqli(mproved) instead. , should escape posted values, important!
Comments
Post a Comment