php - Echo out user information in the same table to their page base on their store information without echoing out the same information to another user -


first of stored users in same table , created page called welcome.php, want echoing out user info mysql based on entry.

now when created first user , echo out welcome.php, comes out table, , if create user info in same table echo out @ same welcome.php based on user login info such as, if create user called john fred etc , user called michael kenneth etc.

so user john fred comes out welcome.php information same table, , user michael kenneth doesn't come welcome.php when sign user michael kenneth instead shows user john fred. don't know error comes from; maybe login.php, or welcome.php.

here code echoing in welcome.php

<?php  $tnumber2 = "{$_session['tnumber2']}";  //  connect database  $db = mysql_connect("$sname","$uname","$pname") or die("could not connect database.");  $select = mysql_select_db("$dname") or die("could not select database.");    $sql="select * `$tname` limit 0, 25 ;";  $result=mysql_query($sql); $rows=mysql_fetch_array($result);  ?>  <? echo $rows['tnumber2']; ?> 

another script other user info store table:

<?php  //  connect database $tnumber2 = "{$_session['tnumber2']}";  $db = mysql_connect("$sname","$uname","$pname") or die("could not connect database.");  $select = mysql_select_db("$dname") or die("could not select database.");    $sql="select * `$upname` limit 0, 25 ;";  $result=mysql_query($sql); ?>  <?php while($rows=mysql_fetch_array($result)){ // start looping table row  ?>  <? echo $rows['pdate']; ?>  <?php // exit looping , close connection  } mysql_close(); ?> 

and here login.php in case using 1 input form:

<?php session_start(); ob_start(); ?> <?php  if ($_post['submit']) {     $tnumber2 = $_post['user'];      if ($tnumber2) {             require("connect.php");              $query = mysql_query("select * users tnumber2='$tnumber2'");             $numrows = mysql_num_rows($query);             if($numrows == 1) {                 $row = mysql_fetch_assoc($query);                 $id = $row['id'];                 $tnumber2 = $row['tnumber2'];                  if ($tnumber2 == $tnumber2) {                            $_session['id'] = $id;                         $_session['tnumber2'] = $tnumber2;                          header("location: welcome.php");                         }                      }                     else                         include "error.php";       } } ?> 

i have try can on maybe might fool think such thing possible not php professional learner, please gladly appreciated.

assuming session has indeed stored data of logged-in user, need change "welcome.php" reads correct user where clause:

<?php  // retrieve id of user (and untaint too) $id = (int) $_session['id'];   //  connect database (i've removed unnecessary quotes) $db = mysql_connect($sname, $uname, $pname) or die("could not connect database.");  $select = mysql_select_db($dname) or die("could not select database.");   // here query users table, we're selecting 1 user here $sql="select * `users` `id` = $id;";  $result = mysql_query($sql); $rows = mysql_fetch_array($result);  ?>  <!-- let's see in rows now, should 1 record --> <?php print_r($rows) ?> 

i advise try understand each part of code above, , indeed same code have - don't copy-and-paste without knowing each bit does. if stuck on something, don't afraid in manual!

i've used print_r dump row result - can use contents of determine columns , other data wish extract out of it. after have done that, print_r can removed.

bear in mind login not testing password correctness - checks has entered particular username in login.php. if want users log on username , password, needs designed , implemented well. there many questions on site best-practice techniques on how that, if that's of interest you.

it has, incidentally, been rather difficult understand doing. don't think problem english, seems fine me. rather, it's worth remembering write in short sentences (no more 20 words, say) , short paragraphs (no more 4 or 5 sentences). , keep descriptions short can - makes difference between people helping , deciding don't understand trying do. expect advice relevant in native language well!

also, remember add useful information question can, , if people ask clarification, make sure answer questions. remember people here volunteers, , need make job easy possible.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -