Want to print data Kindly urgent

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
altafhpatel
Forum Newbie
Posts: 1
Joined: Thu Jan 05, 2012 6:10 am

Want to print data Kindly urgent

Post by altafhpatel »

I am using this login and registration form see
this checks user name and password and show form

Code: Select all

<head>
<title>login page</title>
</head>
<body bgcolor="black" style="color:gray">
<form action="index.php" method=get>
<h1 align="center" style="color:gray" >Welcome to this simple application</h1>
<?php
session_start(); 
if($_SESSION["logged"])
{
     print_secure_content();
}
else {
    if(!$_SESSION["logging"])
    {  
    $_SESSION["logging"]=true;
    loginform();
    }
     else if($_SESSION["logging"])
       {
         $number_of_rows=checkpass();
         if($number_of_rows==1)
            {    
             $_SESSION[user]=$_GET[userlogin];
             $_SESSION[logged]=true;
             print"<h1>you have loged in successfully</h1>";
             print_secure_content();
            }
            else{
                   print "wrong pawssword or username, please try again";    
                loginform();
            }
        }
     }
this is the functions

fucntion login form

Code: Select all

function loginform()
{
print "please enter your login information to proceed with our site";
print ("<table border='2'><tr><td>username</td><td><input type='text' name='userlogin' size'20'></td></tr><tr><td>password</td><td><input type='password' name='password' size'20'></td></tr></table>");
print "<input type='submit' >";    
print "<h3><a href='registerform.php'>register now!</a></h3>";    
}
it checks the passwords

Code: Select all

function checkpass()
{
$servername="localhost";
$username="root";
$conn=  mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("test",$conn);
$sql="select * from users where name='$_GET[userlogin]' and password='$_GET[password]'";
$result=mysql_query($sql,$conn) or die(mysql_error());
return  mysql_num_rows($result);
}
now it works fine but i want to show the other data from this table users
but i don't know how to get this
kindly help me
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Want to print data Kindly urgent

Post by social_experiment »

Code: Select all

<?php
$qry = "SELECT field FROM table";
$sql = mysql_query($qry);

while ($array = mysql_fetch_array($sql)) {
  echo $array['field'];
}
?>
This is the basic idea behind displaying data from the database. There is a query which selects which fields you want to display, the query is passed to the mysql_query() function. Then a function like mysql_fetch_array() is used to fetch data in the form of an array. Finally you access the data like you would in an array. You need to change 'field' to the fields you wish to display and change 'table' to the related database table.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply