i have a database (hello) and it has 2 tables 1. login_tbl and 2. users_tbl
both contains the 3 fields id,username,password and id,first_name,last_name respectively.
now plz help me to write the php code according to this which helps to search the users details in users_tbl
and fetch all the records.
thnks

nothing.... now i want code in php

If you check this page you will find several MySQL code snippets to get you started. I recommend MySQLi or PDO examples.

ok... thnkuuuu

Use innerjoin.

no dear i want code

then u better find someone that is willing to write it for you. coz no one here will just shove the answer in your mounth. better yet show us what u have and lots of guys here will be willing to help you out.

ok... now i have a code. all works fine but the data inserted by insert.php in not correctly shown on show.php page but its inseted correct in database
login.php

<html>

<head>

<title>Login</title>

</head>

<body>

<?php

if(isset($_POST['save'])){

//include database configuration

include 'connect.php';

extract($_REQUEST);

//sql insert statement

$query=mysqli_query($conn,"insert into login_tbl SET username='$username', password='$password'") or die(mysqli_error($conn));

//insert query to the database

if($query){

//if successful query

echo "New record was saved.";

}

}

?>

<!--we have our html form here where user information will be entered-->

<form action='#' method='post' border='0'>

<table>

<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></td>

<td>

<input type='submit' value='Save' name="save" />

</td>

</tr>

</table>

</form>

</body>

</html>

insert.php

<html>

<head>

<title>Insert</title>

</head>

<body>

<?php

if(isset($_POST['save'])){

//include database connection

include 'connect.php';

extract($_REQUEST);

//sql insert statement

$query=mysqli_query($conn,"insert into users_tbl SET first_name='$firstname', last_name='$lastname'") or die(mysqli_error($conn));

//insert query to the database

if($query){

//if successful query

echo "New record was saved.";

}

}

?>

<form action='#' method='post' border='0'>

<table>

<tr>

<td>Firstname</td>

<td><input type='text' name='firstname' /></td>

</tr>

<tr>

<td>Lastname</td>

<td><input type='text' name='lastname' /></td>

</tr>

<tr>

<td></td>

<td>

<input type='submit' value='Save' name="save" />

</td>

</tr>

</table>

</form>

</body>

</html>

show.php

<?php

//include database connection

include 'connect.php';

//selecting records

$sql="select first_name, last_name from users_tbl";
$sql1="select username, password from login_tbl";

//query the database

$rs=mysqli_query($conn,$sql) or die($sql.">>".mysqli_error($conn));
$rs1=mysqli_query($conn,$sql1) or die($sql1.">>".mysqli_error($conn));

//count how many records found

$num=mysqli_num_rows($rs);
$num1=mysqli_num_rows($rs1);

if($num>0){ //check if more than 0 record found

?>

<table border='1'>

<tr>

<th>Firstname</th>

<th>Lastname</th>

<th>Username</th>

<th>Password</th>

</tr>

<?php

//retrieve our table contents

while($row=mysqli_fetch_array($rs))
while($row1=mysqli_fetch_array($rs1)){

//extract row

//this will make $row['firstname'] to

//just $firstname only

extract($row);
extract($row1);

//creating new table row per record

?>

<tr>

<td><?php echo $first_name; ?></td>

<td><?php echo $last_name; ?></td>

<td><?php echo $username; ?></td>

<td><?php echo $password; ?></td>

</tr>

<?php

}

?>

</table>

<?php

}else{ //if no records found

echo "No records found.";

}

?>

connect.php

<?php

$dbhost = "localhost";

$dbuser = "root";

$dbpass = "";

$dbname = "hello";

$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname) or die ('Error connecting to mysql');

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.