On my website i have an admin page where i want to be able to update information in the database, using a form.
This is the code im using to enter information and update what is in my database:
adminform.php
<html>
<head>
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body>
<header id="header">
<h1>SafeTNet</h1>
<nav id="nav">
<ul>
<li>Admin Page Only</li>
<li></li>
<li>Logout </li>
</ul>
</nav>
</header>
<h1> Select a member </h1>
<br />
<select name="members" onchange="showUser(this.value)">
<option value="">Select a member email</option>
<?php
$query = "SELECT * FROM members";
$mysqli = new mysqli('localhost','root','root','SafeTNetD');
$result = $mysqli->query($query);
while($row = $result->fetch_assoc())
echo '<option value="'.$row["email"].'">'.$row["email"].'</option>';
?>
</select>
<div id="signup">
<h2>Update Your Member Information</h2>
<form method="post" action="admin1.php">
<table>
<tr>
<td>Email</td>
<td><input type="text" name="email" required="required"></td>
</tr>
<tr>
</tr>
<tr>
<td>City </td>
<td><input type="text" name="city"></td>
</tr>
<tr>
</tr>
<tr>
</table>
<br><br>
<div id="buttons">
<input type="submit">
</div>
</body>
</html>
admin1.php
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body>
<header id="header">
<h1>SafeTNet</h1>
<nav id="nav">
<ul>
<li>Admin Page Only</li>
<li></li>
<li>Logout</li>
</ul>
</nav>
</header>
<br />
<?php
$query = "SELECT * FROM members";
$mysqli = new mysqli('localhost','root','root','SafeTNetD');
$result = $mysqli->query($query);
while($row = $result->fetch_assoc())
echo '<option value="'.$row["email"].'">'.$row["email"].'</option>';
?>
</select>
<br />
<?php
$q=$row["email"];
$mysqli = new mysqli('localhost','root','root','members');
$sql = "SELECT * FROM members WHERE email='".$q."'";
if(array_key_exists('_submit_check', $_POST))
{
$email = $_POST['email'];
$city = $_POST['city'];
$sql = "UPDATE members SET city = '$city' WHERE email = '$q'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
?>
<br><br><br>
<footer id="footer">
<img src="logo.jpg" height="50px">
<ul class="copyright">
<li>© SafeTNet. All rights reserved.</li><li> 2016</li>
</ul>
</footer>
</body>
</html>
I can get the form to run but cant get the information to change in the database or echo to the screen.
Thank you in advance.
if(array_key_exists('_submit_check', $_POST))
{
$email = $_POST['email'];
$city = $_POST['city'];
$sql = "UPDATE members SET city = '$city' WHERE email = '$q'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
There is no element called '_submit_check' in your form. I guess you forgot the name attribute of your submit-button.
Your script is very vulnerable to SQL-Injection. You really should not simply throw the userinput into your query. You can use mysqli_real_escape_string() or Prepared Statements to protect your application.
To improve the readability of your code you could change the structure a little. In your admin1.php you should do the business logic before outputting any html. So you would first check if the form has been sent, then you do the database operation. The result of the check or the success/error-message of the database operation can be written into a variable until you output the content of your site.
This way everybody who starts reading the code immediately knows 'alright, this script is the target of some form and accesses the database for some write-operation'.
Related
I'm trying to display an image which have been stored in MySQL, but haven't been able to get a success just yet. Apparently echoing the table header (img) gives me back something like this
In addition I would like to be able to add the image in the website itself rather than using the phpmyadmin and inserting the image there.
As of now this is the code I have for the standing.php page
<?php
require_once('database.php');
// Get all categories
$query = 'SELECT * FROM categories
ORDER BY categoryID';
$statement = $db->prepare($query);
$statement->execute();
$teams = $statement->fetchAll();
$statement->closeCursor();
?>
<!DOCTYPE html>
<html>
<!-- the head section -->
<head>
<title>NBA</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="shortcut icon" type="image/png" href="images/favicon.ico"/>
</head>
<!-- the body section -->
<body>
<main id="standingListMain">
<h1 id="addCategoryh1">Team Standings</h1>
<table id="standingListTable">
<tr>
<th>Team</th>
<th> </th>
</tr>
<?php foreach ($teams as $team) : ?>
<tr>
<td><?php echo $team['categoryID']; ?></td>
<td>
<?php echo $team['categoryName']; ?>
<?php echo $team['img']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<br>
</main>
<!-- <footer id="standingListFooter">
<p>© <?php echo date("Y"); ?> NBA</p>
</footer> -->
</body>
</html>
Basically, the user can add or remove a team from the team_list.php page and view it on the standings page
<?php
require_once('../Model/database.php');
// Get all categories
$query = 'SELECT * FROM categories
ORDER BY categoryID';
$statement = $db->prepare($query);
$statement->execute();
$teams = $statement->fetchAll();
$statement->closeCursor();
?>
<!DOCTYPE html>
<html>
<!-- the head section -->
<head>
<title>NBA</title>
<link rel="stylesheet" type="text/css" href="../css/index.css">
<link rel="shortcut icon" type="image/png" href="images/favicon.ico"/>
</head>
<!-- the body section -->
<body>
<main>
<h1 id="addCategoryh1">Teams</h1>
<table id="categoryListTable">
<tr>
<th>Name</th>
<th> </th>
</tr>
<?php foreach ($teams as $team) : ?>
<tr>
<td><?php echo $team['categoryName']; ?></td>
<td>
<form action="delete_team.php" method="post"
id="delete_product_form">
<input type="hidden" name="team_id"
value="<?php echo $team['categoryID']; ?>">
<input id="deleteCategoryList" type="submit" value="Delete">
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<br>
<h2 id="add_category_h2">Add Team</h2>
<form action="add_team.php" method="post"
id="add_category_form">
<label>Name:</label>
<input type="input" name="name">
<input id="add_category_button" type="submit" value="Add">
</form>
<br>
<p>View Team List</p>
</main>
<footer id="categoryListFooter">
<p>© <?php echo date("Y"); ?> NBA</p>
</footer>
</body>
</html>
Code above is the team_list.php page and below is the code to connect to the database called the add_team.php
<?php
// Get the team data
$name = filter_input(INPUT_POST, 'name');
// Validate inputs
if ($name == null) {
$error = "Invalid team data. Check all fields and try again.";
include('../Error/error.php');
} else {
require_once('../Model/database.php');
// Add the product to the database
$query = 'INSERT INTO categories (categoryName)
VALUES (:team_name)';
$statement = $db->prepare($query);
$statement->bindValue(':team_name', $name);
$statement->execute();
$statement->closeCursor();
// Display the team List page
include('team_list.php');
}
?>
The image above shows the page where u can add or remove a team.
For testing purposes
First you need to know if the Image really exist. Let's assume that in your database you have an image with category Id of 1. Thus create another file, eg "image.php".
(Please ensure that this code runs correctly. I have not tested it but it should work for you).
image.php
<?php
require_once('database.php');
// Get all categories
$query = "SELECT img FROM categories where categoryID=1";
$statement = $db->prepare($query);
$statement->execute();
$num = $statement->rowCount();
if( $num ){
$teams = $statement->fetchAll();
// Ensure to specify header with content type,
// you can do header("Content-type: image/jpg"); for jpg,
// header("Content-type: image/gif"); for gif, etc.
header("Content-type: image/png");
//display the image file
print $teams['img'];
exit;
}else{
//echo no image found with that Category Id.
}
?>
Then in your "standing.php", remove this code:
<?php echo $team['img']; ?>
and replace it with:
<!– "1" is the categoryID id of the image to be displayed –>
<img src="image.php?id=1" />
i have declared a session_start() function in the start of both the pages but still the variable is not passing on to the session variable please help
this is where i have included my login.php
<?php
include("template/header.php");
include("template/content.php");
include("template/footer.php");
include("login.php");
?>
this my login.php file where i have passed $email variable to SESSION
<?php
session_start();
include("includes/connection.php");
if(isset($_POST['login'])){
$email= mysqli_real_escape_string($con,$_POST['email']);
$pass= mysqli_real_escape_string($con,$_POST['pass']);
$select_user = "select * from users where user_email= '$email' AND
user_pass='$pass' AND status='verified'";
$query = mysqli_query($con,$select_user);
$check_user= mysqli_num_rows($query);
if($check_user===1){
$_SESSION['usermail']=$email;
echo "<script>window.open('home.php','_self')</script>";
} else {
echo "<script>alert('incorrect details try again')</script>";
}
}
?>
and this is where i have tried to access the session variable but it says undefined:usermail but i dont understand i am giving the session_start() at the beginning and have checked that $email is successfully getting its value from the database then why this is not working
<?php
session_start();
include("includes/connection.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome User!</title>
<link rel="stylesheet" href="styles/home_style.css" media="all"/>
</head>
<body>
<!--container starts-->
<div class="container">
<!--header wrapper starts here-->
<div id="head_wrap">
<!--header starts-->
<div id="header">
<ul id="menu">
<li>Home</li>
<li>Members</li>
<strong>Topics:</strong>
<?php
$get_topics = "select * from topics";
$run_topics= mysqli_query($con,$get_topics);
while($row=mysqli_fetch_array($run_topics)){
$topic_id = $row['topic_id'];
$topic_title = $row['topic_name'];
echo "<li><a href='topic.php?
topic=$topic_id'>$topic_title</a></li>";
}
?>
</ul>
<form method="get" action="results.php" id="form1">
<input type="text" name="user_query" placeholder="search a
topic"/>
<input type="submit" name="search" value="search"/>
</form>
</div><!--header ends-->
</div><!--head wrap ends-->
<!--content area starts-->
<div class="content">
<!--user timeline starts here-->
<div id="user_timeline">
<div id="user_details">
<?php
$user=$_SESSION['usermail'];
var_dump($_SESSION);
$get_user="select * from users where user_email='$user'";
$run_user= mysqli_query($con,$get_user);
$row=mysqli_fetch_array($run_user);
$user_id= $row['user_id'];
$user_name= $row['user_name'];
$user_country= $row['user_country'];
$user_image= $row['user_image'];
$register_date= $row['user_reg_date'];
$last_login= $row['user_last_login'];
$user_posts="select * from posts where user_id='$user_id'";
$run_posts = mysqli_query($con,$user_posts);
$posts =mysqli_num_rows($run_posts);
//getting the number of unread messages
$sel_msg = "select * from messages where receiver='$user_id' AND
status='unread' ORDER by 1 DESC";
$run_msg = mysqli_query($con,$sel_msg);
$count_msg = mysqli_num_rows($run_msg);
echo "
<center>
<img src='users/default.png' width='200' height='200'?>
</center>
<dev id='user_mention'>
<p><strong>Country:</strong>$user_country</p>
<p><strong>Last Login:</strong>$last_login</p>
<p><strong>Member Since:</strong>$register_date</p>
<p><a href='my_messages.php?inbox&u_id=$user_id'>Messages
($count_msg)</a></p>
<p><a href='edit_profile.php?u_id=$user_id'>Edit my account</a>
</p>
<p><a href='logout.php'>Logout</a></p>
</div>
";
?>
</div><!--user details ends here-->
</div><!--user timeline ends here-->
</div><!--content area ends-->
</div><!--container ends-->
</body>
</html>
Hey there stackoverflow users, i have come upon a very confusing problem that I cant seem to move past. I am creating a forum type web page and am currently working on the comments section. I have a form that uses the post method to send your comment as well as a hidden input to store the threads ID. I will post the entire php file below just to make sure nothing is left out.
<?php
session_start();
parse_str($_SERVER['QUERY_STRING'], $link);
$threadID = $link['ID'];
require("config.php");
$connection = mysqli_connect($host, $user, $password, $database);
$error = mysqli_connect_error();
if($error != null) {
$output = "<p>Unable to connect to database!</p>";
exit($output);
} else {
//Get Thread Data
$query = "SELECT username, title, content FROM threads, users WHERE threads.ID = $threadID AND users.ID = threads.makerID;";
$results = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($results);
//Get Comment Data
$query = "SELECT username, comment FROM comments, users WHERE threadID = $threadID AND users.ID = comments.makerID;";
$results = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($results);
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<title>BodyweightMate</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/styling.css"/>
</head>
<body>
<!--Top masthead-->
<header class="masthead" id="top">
<h1 class="masthead-title"> Welcome To BodyweightMate </h1>
</header>
<!--Navigation bar-->
<nav class="navbar">
<table class="navbar-table">
<tr>
<!--Logo-->
<td>
<a class="navbar-brand" href="main.php">
<img src="../images/logo.jpg" alt="BodyweightMate" height="30" width="30">
</a>
</td>
<!--Login/Profile-->
<?php if(isset($_SESSION['login_user'])) {
echo"<td><a class=\"navbar-profile\" href=\"profile.php\"> Profile </a></td>";
echo"<td><a class=\"navbar-logout\" href=\"logout.php\"> Logout </a></td>";
} else {
echo"<td><a class=\"navbar-login\" href=\"login.php\"> Login </a></td>";
}?>
</tr>
</table>
</nav>
<!--Main portion-->
<section class="content-section">
<article>
<h3><?php echo $row['username']. ": " .$row['title']; ?></h3>
<p><?php echo $row['content']; ?></p>
<br>
<h3>Comments</h3>
<p>Some annoying user: Gr8 B8 M8</p>
<p>Annoying users friend: I R8 8/8</p>
</article>
<div>
<!--If logged in, ability to comment-->
<?php if(isset($_SESSION['login_user'])): ?>
<form role="comment-form" method="POST" action="processcomment.php" id="mainForm">
<input type="hidden" value="$threadID" name="threadID">
<div class="form-group">
<label for="comment">Comment </label> <br>
<textarea class="comment-text" name="comment" rows="2" maxlength="255"></textarea>
</div> <br>
<input type="Submit" class="btn-newcomment" value="Submit Comment" name="submit">
</form>
<?php endif ?>
</div>
</section>
<!--Right portion-->
<aside class="content-aside">
<div>
<!--If logged in, be able to create a thread-->
<?php
if(isset($_SESSION['login_user'])) {
echo"<form method=\"post\" action=\"makethread.php\">";
echo"<input type=\"submit\" class=\"btn-newthread\" value=\"Create New Thread\" name=\"submit\">";
echo"</form>";
}
?>
</div>
<!--Info-->
<div>
<p> GOING TO NEED A SEARCH FUNCTION HERE
This is the cool little aside section. It will always be there to provide you with some very nice little details, helpful links, maybe a list of moderators? who knows! The uses are endless when you have a beautiful little aside like this one! Here are a few very useful bodyweight fitness links to get us started :D </p>
</div>
<br>
<div>
<ul class="content-aside-links">
<li>
Reddit's Bodyweightfitness Forum
</li>
<li>
Reddit's Bodyweightfitness RR
</li>
<li>
Antranik's Bodyweightfitness Routine
</li>
</ul>
</div>
<div></div>
</aside>
<!--Footer -->
<footer class="footer">
<div>
<p> Use of this site constitutes acceptance of our User Agreement © 2017 BodyweightMate inc. All rights reserved. </p>
</div>
</footer>
</body>
</html>
The error is occurring under the main portion where i check if a user is logged in, and if they are add a short form consisting of a message, a text area, and a submit button. This form sends the information to the following php file.
<?php
session_start();
if(!isset($_SESSION['login_user'])) { header("location: main.php"); }
?>
<!DOCTYPE html>
<html>
<body>
<?php
require("config.php");
$connection = mysqli_connect($host, $user, $password, $database);
$error = mysqli_connect_error();
if($error != null) {
$output = "<p>Unable to connect to database!</p>";
exit($output);
} else {
//Validation
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$comment = $_POST['comment'];
$threadID = $_POST['threadID'];
$user = $_SESSION['login_user'];
} else {
//Redirect back to register
echo"<p>Form must use post or input was bypassed.</p>";
echo" Return to home page. ";
mysqli_close($connection);
exit();
}
There is no issue with connecting to the database, and I don't believe the remainder of the code is necessary to help me with this error since that one if statement of checking if the form is using post is failing and the else statement is always called. Why is this? i have rewritten the form multiple times ensuring that its properly structured and using post yet it fails every time!
I am trying to display some variables and forms like a inbox type messages with "echo".
The problem is that the echo is not displayed and don't know how to repair it.
When i click on subject field on the subject title should show the "echo" but it doesn't.
Bellow is the code:
<?php
if(isset($_GET['msg_id'])){
$get_id = $_GET['msg_id'];
$sel_message = "select * from messages where msg_id='$get_id'";
$run_message = mysqli_query($con, $sel_message);
$row_message = mysqli_fetch_array($run_message);
$msg_subject = $row_message['msg_sub'];
$msg_topic = $row_message['msg_topic'];
$reply_content = $row_message['reply'];
//updating the unread message to read
$update_unread = "update messages set status='read' where msg_id='$get_id'";
$run_unread = mysqli_query($con, $update_unread);
echo "
<center><br />
<hr>
<h2>$msg_subject</h2><br/>
<p><b>Message:</b>$msg_topic</p><br />
<p><b>My reply:</b>$reply_content</p><br/>
<form action='' method='post'>
<textarea cols='60' rows='10' name='reply'></textarea><br /><br />
<input type='submit' name='msg_reply' value='Reply to this' />
</form>
</center>
";
}
if(isset($_POST['msg_reply'])){
$user_reply = $_POST['reply'];
if($reply_content!='no_reply'){
echo "<h2 align='center'>This message was already replied!</h2>";
exit();
} else {
$update_msg = "update messages set reply='$user_reply' where msg_id='$get_id'";
$run_update = mysqli_query($con, $update_msg);
echo "<h2 align='center'>Message was replied!</h2>";
}
}
}
?>
Bellow is the all code from my_messages.php. I decided to put it here all the code to avoid any questions regarding missing code information. Maybe will help to get the error.
The problem is at the end of the code when i try to click on my inbox and the messages are not displayed when i click on the sender subject. The form is not shown with the echo function.
<?php
session_start();
include("includes/connection.php");
include("functions/functions.php");
if(!isset($_SESSION['user_email'])){
header("location: index.php");
}
else{
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Welcome User!</title>
<link rel="stylesheet" type="text/css" href="styles/home_style.css" media="all">
</head>
<body>
<!-- Container starts -->
<div class="container">
<!-- Header Wrapper Starts -->
<div id="head_wrap">
<!-- Header Starts -->
<div id="header">
<ul id="menu">
<li>Home</li>
<li>Memebers</li>
<strong>Topics:</strong>
<?php
$get_topics = "select * from topics";
$run_topics = mysqli_query($con, $get_topics);
while($row= mysqli_fetch_array($run_topics)){
$topic_id = $row['topic_id'];
$topic_title = $row['topic_title'];
echo "<li><a href='topic.php?topic=$topic_id'>$topic_title</a></li>";
}
?>
</ul>
<form method="get" action="results.php" id="form1">
<input type="text" name="user_query" placeholder="Search a topic"/>
<input type="submit" name="search" value="Search"/>
</form>
</div>
<!-- Header Ends -->
</div>
<!-- Header Wrapper Ends -->
<!-- Content area starts -->
<div class="content">
<!-- User timeline starts -->
<div id="user_timeline">
<div id="user_details">
<?php
$user = $_SESSION['user_email'];
$get_user = "select * from users where user_email='$user'";
$run_user = mysqli_query($con, $get_user);
$row = mysqli_fetch_array($run_user);
$user_id = $row['user_id'];
$user_name = $row['user_name'];
$user_country = $row['user_country'];
$user_image = $row['user_image'];
$register_date = $row['register_date'];
$last_login = $row['last_login'];
$user_posts = "select * from posts where user_id='$user_id'";
$run_posts = mysqli_query($con, $user_posts);
$posts = mysqli_num_rows($run_posts);
//getting the number of unread messages
$sel_msg = "select * from messages where receiver='$user_id' AND status='unread' order by 1 DESC";
$run_msg = mysqli_query($con, $sel_msg);
$count_msg = mysqli_num_rows($run_msg);
echo "
<center><img src='user/user_images/$user_image' width='240' height='240'/></center>
<div id='user_mention'>
<p><strong>Name:<strong> $user_name</p>
<p><strong>Country:<strong> $user_country</p>
<p><strong>Last Login:<strong> $last_login</p>
<p><strong>Member Since:<strong> $register_date</p>
<p><a href='my_messages.php?inbox&u_id=$user_id'>Messages ($count_msg)</a></p>
<p><a href='my_posts.php?u_id=$user_id'>My Posts ($posts)</a></p>
<p><a href='edit_profile.php?u_id=$user_id'>Edit My Account</a></p>
<p><a href='logout.php'>Logout</a></p>
</div>
";
?>
</div>
</div>
<!-- User timeline ends -->
<!-- Content timeline starts -->
<div id="msg" align="center">
<p align="center">
My Inbox ||
Sent Items
</p>
<?php
if(isset($_GET['sent'])){
include("sent.php");
}
?>
<?php if(isset($_GET['inbox'])){ ?>
<table width="800" align="center">
<tr>
<th>Sender:</th>
<th>Subject</th>
<th>Date</th>
<th>Reply</th>
</tr>
<?php
$sel_msg = "select * from messages where receiver='$user_id' order by 1 DESC";
$run_msg = mysqli_query($con, $sel_msg);
$count_msg = mysqli_num_rows($run_msg);
while($row_msg= mysqli_fetch_array($run_msg)){
$msg_id = $row_msg['msg_id'];
$msg_receiver = $row_msg['receiver'];
$msg_sender = $row_msg['sender'];
$msg_sub = $row_msg['msg_sub'];
$msg_topic = $row_msg['msg_topic'];
$msg_id = $row_msg['msg_id'];
$msg_date = $row_msg['msg_date'];
$get_sender = "select * from users where user_id='$msg_sender'";
$run_sender = mysqli_query($con, $get_sender);
$row = mysqli_fetch_array($run_sender);
$sender_name = $row['user_name'];
?>
<tr align="center">
<td>
<a href="user_profile.php?u_id=<?php echo $msg_sender; ?>" target="_blank">
<?php echo $sender_name; ?>
</a>
</td>
<td><?php echo $msg_sub; ?></td>
<td><?php echo $msg_date; ?></td>
<td>Reply</td>
</tr>
<?php } ?>
</table>
<?php
if(isset($_GET['msg_id'])){
$get_id = $_GET['msg_id'];
$sel_message = "select * from messages where msg_id='$get_id'";
$run_message = mysqli_query($con, $sel_message);
$row_message = mysqli_fetch_array($run_message);
$msg_subject = $row_message['msg_sub'];
$msg_topic = $row_message['msg_topic'];
$reply_content = $row_message['reply'];
//updating the unread message to read
$update_unread = "update messages set status='read' where msg_id='$get_id'";
$run_unread = mysqli_query($con, $update_unread);
echo "<center><br/><hr>
<h2>$msg_subject</h2><br/>
<p><b>Message:</b>$msg_topic</p><br/>
<p><b>My reply:</b>$reply_content</p>
<br/>
<form action='' method='post'>
<textarea cols='60' rows='10' name='reply'></textarea><br/><br/>
<input type='submit' name='msg_reply' value='Reply to this'/>
</form>
</center>
";
}
if(isset($_POST['msg_reply'])){
$user_reply = $_POST['reply'];
if($reply_content!='no_reply'){
echo "<h2 align='center'>This message was already replied!</h2>";
exit();
}
else{
$update_msg = "update messages set reply='$user_reply' where msg_id='$get_id'";
$run_update = mysqli_query($con, $update_msg);
echo "<h2 align='center'>Message was replied!</h2>";
}
}
}
?>
</div>
</div>
<!-- Content area ends -->
</div>
<!-- Container ends -->
</body>
</html>
<?php } ?>
var_dump( $row_message)
after fetching from database to see what's in it.
Please consider changing this line
$row_message = mysqli_fetch_array($run_message);
To this
$row_message = mysqli_fetch_assoc($run_message);
mysqli_fetch_array does not return associative array as you want to access further in your code.
Please Make sure you are passing msg_id in query string like someurl?msg_id=1, else you won't see anything inside
if(isset($_GET['msg_id'])){
/* get msg_id details from db and show */
}
this is because here we are checking if msg_id is set then show content. ;)
For some reason my table I'm trying to create doesn't show up on my page. The page use to work perfectly and I can't figure out why its not working now.
My program only works when I set
$_SESSION['loginname']="jordan#yahoo.com";
or $_SESSION['loginname']="mary666#yahoo.com";
and so on.
I've already started a "$_Session" on my previous page with the name $_SESSION['loginname']; I've echoed out the Session over and over to see if it is passing right from one page to another and down the current page and it does.
Why isn't my $_SESSION allowing my MYSQL code to run the loop to display my data from my database? code provided below:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>User Account</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>Home</li>
<li class="current">Account Info</li>
<li>Quiz</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">
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database = "basketball_database";
$table = "users";
$session_login = $_SESSION['loginname'];
$con = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MYsql");
// echo "Connected to mysql<br>";
mysql_select_db("$database")
or die("Could not select Basketball_database");
//echo "Connected to database";
$mysql = "SELECT * FROM $table WHERE login_name='$_SESSION[loginname]'";
$mydata = mysql_query($mysql,$con);
while($records = mysql_fetch_array($mydata)){
//create table
echo "<table border=1
<tr>
<th>User ID</th></tr>
<tr>
<th>Login Name</th></tr>
<tr>
<th>Password</th></tr>
<tr>
<th>Last Name</th></tr>
<tr>
<th>First Name</th></tr>
<tr>
<th>Account Type</th>
</tr>";
echo "<tr>";
echo "<td>".$records['user_ID']."</td>";
echo "<td>".$records['login_name']."</td>";
echo "<td>".$records['password']."</td>";
echo "<td>".$records['last_name']."</td>";
echo "<td>".$records['first_name']."</td>";
echo "<td>".$records['type']."</td>";
echo "</tr>";
} echo "</table>";
mysql_close();
?>
<div id="content">
<div class="content_item">
</div><!--close content_container-->
</div><!--close content_item-->
</div><!--close content-->
</div><!--close site_content-->
<footer>
Home | Photos | Videos | Schedule | Contact<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>
I do realize that my table is going to look like this
User ID
Login Name
Password
Last Name
First Name
Account Type
1321 jordan#yahoo.com 21duncan oneal jordan athlete