I need help coordinating a way to use a Session[]
$_SESSION['loginname']=jordan@yahoo.com;
$table_name=$_SESSION['loginname'];
to be the name of a table from database.
$username = "root";
$password = "";
$hostname = "localhost";
$database = "basketball_database";
$table = "$table_name";
I keep getting an Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
Which is causing a problem with this set of code
$mysql = "SELECT DISTINCT quiz_name FROM $table";
$mydata = mysql_query($mysql,$con);
while($records = mysql_fetch_array($mydata)){
I then add the mysql_error() and got back
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''jordan@yahoo.com'' at line 1
What am I doing wrong? Thank you
quiz_main.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Quiz</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="main">
<header>
<div id="welcome">
<h2>Prairie View A&M University</h2>
</div><!--close welcome-->
</header>
<nav>
<div id="menubar">
<ul id="nav">
<li><a href="index.php">Home</a></li>
<li><a href="user-account.php">Account Info</a></li>
<li class="current"><a href="quiz_main.php">Quiz</a></li>
         
<?php
if($_SESSION['loginname'])
echo $_SESSION['loginname'].", "."<a href='user-account.php'>Account</a>"." "."<a href='logout.php'>Logout</a>";
else
die("You must login");
?>
</ul>
</div><!--close menubar-->
</nav>
<div id="site_content">
<h2 style="font-size:50px" align="center" > Quiz Page</h2>
<h2> All Quizzes:</h2></br>
<?php
$table_name=$_SESSION['loginname'];
$username = "root";
$password = "";
$hostname = "localhost";
$database = "basketball_database";
$table = $table_name;
$con = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MYsql");
// echo "Connected to mysql<br>";
$db = mysql_select_db("$database")
or die("Could not select Basketball_database");
//echo "Connected to database";
//form for selecting quiz
echo "<form action=\"/xampp/Website_DataBase/Pvamu_website/quiz/index.php\" method=\"post\">";
$mysql = "SELECT DISTINCT quiz_name FROM '$table_name'";
$mydata = mysql_query($mysql,$con);
if($mydata === FALSE) {
die(mysql_error()); // TODO: better error handlin
}
while($records = mysql_fetch_array($mydata)){
$quizname=$records['quiz_name'];
echo "<input type=radio name=name_quiz value='".$records['quiz_name']."'>".$records['quiz_name']."<br>";
}
echo "<input type=submit value=Submit Continue>";
echo "</form>";
?>
<a href="quiz_folder/coach_quizzes.php">Creat a Quiz</a>
<div id="content">
<div class="content_item">
</div><!--close content_container-->
</div><!--close content_item-->
</div><!--close content-->
</div><!--close site_content-->
<footer>
<a href="index.php">Home</a> | <a href="photos.php">Photos</a> | <a href="videos.php">Videos</a> | <a href="schedule.php">Schedule</a> | <a href="contact.php">Contact</a><br/><br/>
</footer>
</div><!--close main-->
<!-- javascript at the bottom for fast page loading -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/image_slide.js"></script>
</body>
</html>