Show only the user's own account in a table that is editable when logged in, PHP Mysql -
i have problem regarding on how can access account able see logged in account, please on mysql statement should use :).
so made page checks if user admin or customer , working.(code below login if admin or customer).
verify if admin or customer page.
<?php include("dbcon.php"); $username=$_post['username']; $password=$_post['password']; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="select * admininfo username='$username' , password='$password' , type='admin'"; $sql1="select * customerinfo username='$username' , password='$password' , type1='customer'"; $result=mysql_query($sql); $result1=mysql_query($sql1); $count = mysql_num_rows($result); $count1 = mysql_num_rows($result1); if ($count==1) { //admin $_session["username"]; $_session["password"]; $_session["type"]; header("location:menu.php"); } elseif ($count1==1) { //customer $_session["username"]; $_session["password"]; $_session["type1"]; header("location:menu1.php"); } else { echo "invalid username or password"; } ?> <?php include('dbcon.php'); ?>
i made page on showing users info shows users existing, want show logged in user dont know mysql statement should use please (code below editing user info p.s. know while loop has shown existing users).
edit user's information page.
<html> <head> </head> <body> <form method="post" action="edit2.php"> <table> <tr><td>first name:</td><td><input type="text" name="fname"></td></tr> <tr><td>last name:</td><td><input type="text" name="lname"></td></tr> <tr><td>address:</td><td><input type="text" name="address"></td></tr> <tr><td>contact number:</td><td><input type="text" name="contactno"></td></tr> <tr><td>username:</td><td><input type="text" name="username"></td></tr> <tr><td>password:</td><td><input type="password" name="password"></td></tr> <tr><td><input type="submit" name="submit" value="save"</td></tr> </table> </form> <table border='1'> <?php $customerquery=mysql_query("select * customerinfo"); while($customerrows=mysql_fetch_array($customerquery)){ ?> <tr> <td>id</td><td>first name</td><td>last name</td><td>address</td><td>contact no</td><td>username</td><td>password</td><td>edit</td> </tr> <tr> <td><?php echo $customerrows['id'];?></td> <td><?php echo $customerrows['fname'];?></td> <td><?php echo $customerrows['lname'];?></td> <td><?php echo $customerrows['address'];?></td> <td><?php echo $customerrows['contactno'];?></td> <td><?php echo $customerrows['username'];?></td> <td><?php echo $customerrows['password'];?></td> <td><a href="edit2.php<?php echo '?id='.$customerrows['id']; ?>">edit</a></td> </tr> <?php } ?> </table> <a href="login1.php">logout</a> </body>
i hope understood well.
you should use $customerquery=mysql_query("select * customerinfo username =".$_session['username']);
and suggestion not use *
select statement, instead use columns need. it's better practice.
edit: also, not sure initiation of session correct. should so: $row = mysql_fetch_assoc($result);
$_session["username"] = $row['username'];
edit2: also, missing session_start(); statement @ beginning of script.
edit3: also, said in 1 comment. practice keep id of table users in session. instead of keeping username in session add $_session['uid'] = $row['id'] , when collecting data user, do: "select * customerinfo id =".$_session['id']
Comments
Post a Comment