I have 2 files that are applicable to this question, myaccount.php and test5.php.
test5 connects to MySQL database, and it is supposed to get the contents of one cell and print it out.
<?php
mysql_connect("mysql8.000webhost.com", "a5470121_tahahn5", "travis2") or
die(mysql_error());
mysql_select_db("a5470121_rhs3") or die(mysql_error());
$result = mysql_query(
"SELECT `user_name`,`Classperiod1` FROM users
WHERE user_name ='" . $_SESSION['user_name'] . "'"
) or die(mysql_error());
$row = mysql_fetch_array( $result );
echo $row['user_name'];
?>
the second file myaccount.php is supposed to put the printout from the php file in html form
<h3> Your First ClassPeriod is<?php echo $row['Classperiod1']?></h3>
I’ve tested this out and using both files with a specific username (ex.John, Andrew etc.) and it will print out the class period fine. When trying to use WHERE with a SESSION variable for some reason stops it from printing. It doesn’t even show any error messages.
Apologies for any mistakes in the code, or if this is a really stupid question. I’m nearly an absolute beginner where PHP and MySQL are concerned
You may want to remove your mysql details from your question!
Are you starting a session using the
session_start()function?http://php.net/manual/en/function.session-start.php
I also don’t see where you’re setting
$_SESSION['user_name']You might try echoing the mysql query you’ve constructed to see what it contains, this can help find out what’s wrong, I’d guess the session variable will be empty.
For example: