mysql - How to display data in PHP from multiple tables for a logged in user? -



mysql - How to display data in PHP from multiple tables for a logged in user? -

there 2 tables

student_info (username,firstname,lastname,password,email,contact age)

and

student_course_info(username{fk},subject,beginner).

i want display info logged in user.

<?php $con=mysqli_connect("localhost","root","","elearning"); // check connection if (mysqli_connect_errno()) echo "failed connect mysql: " . mysqli_connect_error(); if (isset($_session["username"])) { $_post["username"]=$_session["username"]; $user=$_post["username"]; } $result = mysqli_query($con,""select * student_info , student_course_info student_info.username=student_course_info.username , student_info.username=$user , student_course_info.username=$user " "); if($_session["username"]) { echo "<table border='1'>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>username</td>"; echo "<td>" . $row['username'] . "</td>"; echo "<tr>"; echo "<tr>"; echo "<td>first name</td>"; echo "<td>" . $row['firstname'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>last name name</td>"; echo "<td>" . $row['lastname'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>email</td>"; echo "<td>" . $row['email'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>contact</td>"; echo "<td>" . $row['contact'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>age</td>"; echo "<td>" . $row['age'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>subject</td>"; echo "<td>" . $row['subject'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>beginner</td>"; echo "<td>" . $row['beginner'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>level</td>"; echo "<td>" . $row['level'] . "</td>"; echo "</tr>"; } echo "</table>"; } mysqli_close($con); ?>

it gives error @ $user.i suppose either sql query wrong or logged in username not getting stored in $user.

$result = mysqli_query($con, "select * student_info, student_course_info student_info.username = '{$user}' , student_info.username = student_course_info.username ");

of course, should utilize prepared statements instead of building on own. that's point of mysqli.

note used 1 " , not "" @ origin , in end of query. there's no point in checking student_couse_info.username = '{$user}' when explicitely said had same student_course.username.

php mysql

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -