Note that there are some explanatory texts on larger screens.

plurals
  1. POObtain data from php MySQL database not working
    primarykey
    data
    text
    <p>I had my form working perfectly and obtaining data from my database. BUT recently I changed some stuff from my login page in order to assign different pages to different users and once they log in successful, now I'm not having their data(results) being shown in the studentloggedin.php. Thanks by advance</p> <p>I think the problem is from variables I'm assuming.</p> <p>studentloggedin.php</p> <pre><code>&lt;?php //code for display marks $con=mysqli_connect("localhost","kurtfarrugia","1234","kurt_farrugia"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM tblexamresults WHERE admin_usr_name ='$username'"); while($row = mysqli_fetch_array($result)) { echo "English: " . $row['english'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Maltese: " . $row['maltese'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Italian: " . $row['italian'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "PSE: " . $row['pse'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Social Studies: " . $row['social_studies'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Physical Education: " . $row['physical_education'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Drama: " . $row['drama'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Graphical Communication: " . $row['graphical_communication'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Computer Studies: " . $row['computer_studies'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Mathematics: " . $row['mathematics'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Integrated Science: " . $row['integrated_science'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Physics: " . $row['physics'] . " marks"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; $total = $row['english'] + $row['maltese'] + $row['italian'] + $row['pse'] + $row['social_studies'] + $row['physical_education'] + $row['drama'] + $row['graphical_communication'] + $row['computer_studies'] + $row['mathematics'] + $row['integrated_science'] + $row['physics']; $average= $total / 11; echo "Statistics:"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Your average mark is: " . round($average, PHP_ROUND_HALF_UP) . " marks"; } mysqli_close($con); ?&gt; </code></pre> <p>login.php</p> <pre><code>&lt;?php session_start(); //*********Server Information to establish a connection ****** $host = 'localhost'; $user = 'kurtfarrugia'; $password = '1234'; $database = 'kurt_farrugia'; //Open connection $mysqli = new mysqli($host, $user, $password, $database); if (mysqli_connect_errno()) { printf("Connection failed: %s\n", mysqli_connect_error()); exit(); } //***************End Connection Establishment*************************************** //*******Form Information******** $userName = mysql_real_escape_string($_POST['username']); //User Name sent from Form $password = mysql_real_escape_string($_POST['password']); // Password sent from Form //*********retrieving data from Database********** $result = $mysqli-&gt;query("SELECT * FROM tbladmin WHERE admin_usr_name = '".$userName."' and admin_pwd = '".$password."'"); if($row = $result-&gt;fetch_assoc()) { if($row['occupation'] == 'student') { header( "Location: studentloggedin.php" ); } else if($row['occupation'] == 'lecturer') { echo "you are a lecturer"; } } else { header( "Location: login_fail2.php" ); } //**********it ensures that the script does not continue unless the username varaible is not null and not empty if (!empty($_POST['username'])) { $username = mysql_real_escape_string(strip_tags(trim($_POST['username']))); } else { //die('Hey turd, go back and fill in your username!'); header( "Location: login_fail2.php" ); die; } ?&gt; </code></pre> <p>THIS WAS MY PREVIOUS LOGIN PAGE WHICH WORKED GREAT WITH THE PAGE STUDENT LOGGED IN..so what am i missing in the new loginpage?</p> <p>PREVIOUS LOGIN page which worked good </p> <pre><code>&lt;?php session_start(); //*********Server Information to establish a connection ****** $host = 'localhost'; $user = 'kurtfarrugia'; $password = '1234'; $database = 'kurt_farrugia'; $link = mysql_connect($host,$user,$password) or die('Error in Server information'); mysql_select_db($database,$link) or die('Can not Select Databasse'); //***************End Connection Establishment*************************************** //*******Form Information******** $userName = mysql_real_escape_string($_POST['username']); //User Name sent from Form $password = mysql_real_escape_string($_POST['password']); // Password sent from Form $rememberMe = strip_tags($_POST['rememberMe']); setcookie("username", $_POST['username']); //*********retrieving data from Database********** $query = "select * from tbladmin where admin_usr_name='$userName' and admin_pwd='$password'"; $res = mysql_query($query); $rows = mysql_num_rows($res); //**********it ensures that the script does not continue unless the username varaible is not null and not empty if (!empty($_POST['username'])) { $username = mysql_real_escape_string(strip_tags(trim($_POST['username']))); } else { //die('Hey turd, go back and fill in your username!'); header( "Location: login_fail2.php" ); die; } /*if ($rememberMe) { setcookie("loggedIn", "yes", time()+3600); header ("Location: studentloggedin.php" ); die; } else { echo "Username and/or password is incorrect."; } if ($_COOKIE['loggedIn'] == "yes") { header ("Location: studentloggedin.php" ); die(); } */ // HERE is the query //$result2 = mysqli_query($con,"SELECT occupation FROM tbladmin WHERE admin_usr_name ='$username'" == 'student'); //$row == mysqli_fetch_array($result) //**********if $userName and $password will match database, The above function will return 1 row if($rows==1) //{ { //***if the userName and password matches then register a session and redrect user to the studentloggedin.php //$_SESSION['userName']; //$_SESSION['password']; header("location:studentloggedin.php"); } //} else { header( "Location: login_fail2.php" ); die; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload