I have a database, consisting of 8 tables. I am linking my php code with my database, now what i am trying to do is to join two columns of the two separate tables and display them together in my php page. But whenever I execute my page it does not provide any output. Its totally empty. Kindly help me out.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>SlickRed | florida web design</title>
</head>
<body>
<?php
session_start();
$connection = mysql_connect('localhost','root','');
if(!$connection){
die("Database Connection Failed". mysql_error());
}
$select_db = mysql_select_db('hamdard_attendance');
if(!$select_db){
die("Database Connection Failed" . mysql_error());
}
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$query_one = "SELECT * FROM users WHERE user_name = '".$username."' AND user_pass = '".$password."'";
$result = mysql_query($query_one) or die(mysql_error());
$count = mysql_num_rows($result);
if ($count == 1){
$_SESSION['username'] = $username;
}else{
echo "Invalid Login Credentials.";
}
}
if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
}
?>
<div id="container">
<div id="header">
<h1 style="text-align:left">Quality Management<span class="off"> Cell</span></h1>
</div>
<div id="menu">
<ul>
<li class="menuitem"><a href="#">Home</a></li>
<li class="menuitem"><a href="#">Attendance</a></li>
<li class="menuitem"><a href="#">Courses</a></li>
<li class="menuitem"><a href="#">Settings</a></li>
</ul>
<a style="text-align:right" href="#">Logout</a>
</div>
</div>
<div id="content">
<div id="content_top"></div>
<div id="content_main">
<?php echo "<h2> Welcome ".$username."</h2>"?>
<?php
if(isset($_POST['stdnt_name']) && isset($_POST['course_name']) && isset($_POST['stdnt_rfid_tag']) && isset($_POST['student_id']) && isset($_POST['course_id'])){
$username = $_POST['stdnt_name'];
$password = $_POST['course_name'];
$username = $_POST['stdnt_rfid_tag'];
$password = $_POST['student_id'];
$username = $_POST['course_id'];
$query_two = " SELECT s.stdnt_name, c.course_name FROM students s INNER JOIN student_courses sc ON s.stdnt_rfid_tag = sc.student_id INNER JOIN courses c ON sc.course_id = c. course_id";
$result_attendance = mysql_query($query_two) or die(mysql_error());
while($row = mysql_fetch_array($result_attendance)){
echo $row[1]." ".$row[2]."<br/ >";
}}
?>
<p> </p>
<p> </p>
<div id="content_bottom"></div>
<div id="footer"><h3><a href="http://www.bryantsmith.com">florida web design</a></h3></div>
</div>
</div>
</body>
</html>
You say: «But whenever I execute my page it does not provide any output.» This is the key phrase! Even you have problems with wrong SQL this script must produce at least DIVs mentioned in the middle.
The first thing you have to do is to understand if any reply comes to a browser. E.g. using Chrome you press F12 and go to Nenwork tab. Then press F5 and pay attention Status. Is it (OK)200?
If 500 — execute your script using command line to find out php syntax errors.
php -af yourscript.php
It is also possible to see that script does not respond at all (hang). In this case pay attention to mysql_connect('localhost','root','');
This line theoretically may hang the script, and it depends on your apache and browser configuration, how long you can wait for timeout.
PS
Regardless to the question, you are doing dangerous thing when you concatenate (insert) text receved from user directly into SQL code. Leanr more about variable binding and mysql_real_escape_string
function. Actually your code is at risk of sql-injection.