Specifying output location of PHP queries - php

I'm working on a small PHP project as an introduction to the language and am having trouble with formatting database query results. My PHP functions are working correctly, but the results are being displayed above all of the HMTL, like this:
Here's my code, all in a file called index.php. Could somebody point out where I'm going wrong? I want it to display right below the navigation bar (Home, Friend List, etc), How do I specify exactly where I want he PHP to appear in the HTML?
#!/usr/local/bin/php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BumpIt</title>
<!-- Bootstrap -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/custom.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Login PHP -->
<?php
ini_set("display_errors", true);
session_start();
// Store username and password in session variables
if (isset($_POST['signin_user']))
{
$_SESSION['signin_user']=$_POST['signin_user'];
$_SESSION['signin_pass']=$_POST['signin_pass'];
}
// Reset username and pass to that of the session variables
$signin_user = $_SESSION['signin_user'];
$signin_pass = $_SESSION['signin_pass'];
$isSigningIn = $_POST['isSigningIn'];
// Connect to the database, check if error happens
$conn = pg_connect(Redacted*);
$_SESSION['conn'] = $conn;
if (!$conn) {
echo "Connection failed";
exit;
}
/**************************************************************
**************************************************************
***************** FUNCTIONS ***************************
**************************************************************
***************************************************************/
// Load Friend List function
if($_GET['friendList']){friendList();}
function friendList(){
$userID = $_SESSION['userID'];
$query = sprintf("SELECT username FROM (SELECT friend_id FROM friends WHERE user_id = $userID) AS currFriends, users WHERE friend_id = user_id;");
$result = pg_query($_SESSION['conn'], $query);
echo "<table class='table table-striped table-bordered table-hover'>\n";
echo "<caption>Friend List</caption>\n";
while ($line=pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
}
// LOGIC NOT WORKING RIGHT YET (DISPLAYING MULTIPLES OF SAME NAME)
// Find Friends function
if($_POST['search']){searchForFriends();}
function searchForFriends() {
$search = $_POST['search'];
$userID = $_SESSION['userID'];
$query = sprintf("SELECT userName FROM (SELECT friend_id FROM friends WHERE user_id = $userID) AS currFriends, users WHERE friend_id <> users.user_id AND userName ILIKE ( '%%' || "."'".$search."'"." || '%%');");
echo "DEBUG PURPOSES-> SEARCHFORFRIENDS QUERY IS: ".$query;
$result = pg_query($_SESSION['conn'], $query);
echo "<table class='table table-striped table-bordered table-hover'>\n";
echo "<caption>Users</caption>\n";
while ($line=pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
}
?>
<img class="header-logo" src="img/bumpit.png"></img>
<!-- Navigation Bar -->
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li><a id="friendList" href="index.php?friendList=true">Friend List</a></li>
<li>
<a id="logoutBtn" href="index.php?logoutBtn=true">Logout</a>
</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<!-- Search bar -->
<form class="navbar-form navbar-right" role="search" action="index.php?search=true" method="post">
<div class="form-group">
<input name="search" type="text" class="form-control" placeholder="Search">
<input name="isSigningIn" type="hidden" value="1">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<!-- Main content -->
<div class="container">
<div class="starter-template">
<!-- WE WANT THE FRIENDS LIST HERE -->
</div>
</div><!-- /.container -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>

I believe you want to move this:
// Load Friend List function
if($_GET['friendList']){friendList();}
To where you want the friendList printed:
<div class="container">
<div class="starter-template">
<!-- WE WANT THE FRIENDS LIST HERE -->
<?php
// Load Friend List function
if (isset($_GET['friendList'])) { friendList(); }
?>
</div>
</div><!-- /.container -->
You have to add it in <?php ?> and I have also altered if statement so it does not throw a notice if friendList wouldn't be set.

Related

Login page doesn't work as leads to unkown page

Quick Note : This thread was closed for being a duplicate question however the links I found were to do with 'Preventing MySQL Injection Attacks', which was not the answer I was looking for. If reposting this question goes against any guidelines, I don't mind taking this post down.
I've been working on an online booking website and the projects works when I run it on WAMP. I decided to get 1 month hosting on ecowebhosting.com and I've uploaded my project/files as well as change my 'db.php' file to match the settings of phpMyAdmin ( host, username, password, etc. ) however I am not able to sign in.
This is the login page for my website : https://gyazo.com/07f6bb065971b20ba07628d2a68cf1b0
And you are able to register, and the user has been registered when I checked the database on phpMyAdmin however I am not able to login as this occurs when I login in any account : https://gyazo.com/312725f461d4790a99b1b47e97a97066
I thought it was something to do with the 'dashboard.php' file, so I removed the 'include("auth_session.php")' to see if anything was wrong with the file, but it worked as normal. Here is a copy of the code for 'login.php':
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Modern Haircut Designs</title>
<!-- Bootstrap css style sheet -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- For the seperate stuff -->
<link href="coursework_style.css" rel="stylesheet">
<!-- Make sure to add this to the coursework style sheet so less files -->
<link href="login_style.css" rel="stylesheet">
<!-- To enable the javascript shenanigans -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<?php
require('db.php');
session_start();
if (isset($_POST['username'])) {
$username = stripslashes($_REQUEST['username']);
$username = mysqli_real_escape_string($con, $username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con, $password);
$query = "SELECT * FROM `users` WHERE username='$username'
AND password='$password'";
$result = mysqli_query($con, $query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if ($rows == 1) {
$_SESSION['username'] = $username;
header("Location: dashboard.php");
} else {
//Might be necessary to create an error page so the user knows?
header("Location: login.php");
}
} else{
?>
<nav class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/index.php">Modern Haircut Designs</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="actif">Home</li>
<li>Services</li>
<li>Our Team</li>
<li>Reviews</li>
<li>Contact</li>
<li>Login</li>
</ul>
</div>
</div>
</nav>
<section class="login-cover">
<div class="wrapper fadeInDown">
<div id="formContent">
<div class="fadeIn first">
<img src="img/login_icon.jpg" id="icon" alt="MHC Logo" />
</div>
<form method="post" name="login">
<input type="text" id="login" class="fadeIn second" name="username" placeholder="Username" required>
<input type="password" id="password" class="fadeIn third" name="password" placeholder="Password" style="background-color: #f6f6f6;border: none;color: #0d0d0d;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 5px;width: 85%;border: 2px solid #f6f6f6;transition: all;0.5s ease-in-out;border-radius: 5px 5px 5px 5px;" required>
<input type="submit" class="fadeIn fourth" value="Login" name="submit">
</form>
<div class="formFooter">
<a class="underlineHover" href="register.php" id="register">Register Here</a>
<a class="underlineHover" href="#" id="forgot_password">Forgot Password?</a>
</div>
</div>
</div>
</section>
<?php
}
?>
<footer style="bottom: 0; width: 100%;">
crafted with ♥ in Bangladesh by ###
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
As requested, here's a markup for the 'dashboard.php' file:
<?php
//Reminder to include this for the booking part
include("auth_session.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Modern Haircut Designs</title>
<!-- Bootstrap Stuff -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Coursework Style that's seperate -->
<link href="coursework_style.css" rel="stylesheet">
</head>
<body>
<nav class="#">
<div class="container">
<div class="#">
<button type="button" class="#">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="#" href="#top">Modern Haircut Designs</a>
</div>
<div class="#" id="#">
<ul class="#">
<li class="actif">Home</li>
<li>Services</li>
<li>Our Team</li>
<?php
if($_SESSION['username'] == 'admin'){
?><li>Manage Appointments</li><?php
}else{
?><li>View Appointments</li>
<li>Book Appointment</li>
<?php
}
?>
<li>Logout</li>
</ul>
</div>
</div>
</nav>
<div class="cover" id="top">
<div class="cover-text">
<h1>Hey, <?php echo $_SESSION['username']; ?>!</h1>
<p class="lead">Book an appointment now by clicking the button below</p>
Get started!
</div>
</div>
<section id="services">
<h2>Here is a list of the services we provide</h2>
<div class="container">
<div class="row">
#Text about the different types of haircuts
</section>
<section id="team">
<div class="container">
#Pictures and quotes of the different team members
</div>
</section>
<section id="contact-us">
<div class="container">
#ContactInformation here
</div>
</section>
<footer>
crafted with ♥ in Bangladesh by ###
</footer>
<!-- jQuery for javascript stuff-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Bootstrap javascript code / might remove tho -->
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
The solution, as pointed out by #rickdenhaan, was to move the block of php code containing the 'header(###)' section to the start of the file. Another solution I found was to use javascript to open the file.

Codeigniter - Bootstrap table not appearing in view?

UPDATE -
I have got the table to appear, the problem was I had a css file which included display:none; for the table styling.
I am creating an admin panel which displays the current members in the system. I created a table which retrieves data from the database. The problem is for some reason, the table isn't showing up on the page. I have experimented by adding some text to the page, and the text appears, but for some reason when i add a table, it doesn't show? The table appears whenever i remove the header.php file in the controller but when i add that in, the table doesn't show in the view?
Model
<?php
class user_model extends CI_Model{
public function getUser(){
$this->db->select("userID, firstname, lastname, email, username, password, reg_time, activated, image");
$this->db->from("users");
$query = $this->db->get();
return $query->result();
$num_data_returned = $query->num_rows;
if ($num_data_returned < 1) {
echo "No data in database";
exit();
}
}
}
?>
Controller
<?php
class Dashboard extends CI_Controller{
public function __construct(){
parent::__construct();
$this->check_isvalidated();
$this->load->model('user_model');
}
public function index(){
$this->data['user'] = $this->user_model->getUser();
$this->load->view('home/header'); /* header.php file which contains bootstrap css */
$this->load->view('home/admin_view', $this->data);
}
private function check_isvalidated(){
if (! $this->session->userdata('validated')) {
redirect('adminlogin');
}
}
public function logout(){
$this->session->sess_destroy();
redirect('adminlogin');
}
}
?>
View
<div class="col-xs-12" >
<div class="panel panel-default">
<div class="panel-body">
<div class="col-lg-12">
<table>
<caption>System Members</caption>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email Address</th>
<th>Username</th>
<th>Password</th>
<th>Registration Time</th>
<th>Activated</th>
<th>Image</th>
</tr>
</thead>
<tbody>
<?php foreach ($user as $usr) { ?>
<tr>
<td><?=$usr->firstname?></td>
<td><?=$usr->lastname?></td>
<td><?=$usr->email?></td>
<td><?=$usr->username?></td>
<td><?=$usr->password?></td>
<td><?=$usr->reg_time?></td>
<td><?=$usr->activated?></td>
<td><?=$usr->image?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Panna Daily - Admin</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap.css"/>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap-theme.css"/>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/site.css"/>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="<?php echo base_url(); ?>assets/js/jquery-2.2.0.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?php echo site_url('Dashboard/index'); ?>">Admin Dashboard</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="glyphicon glyphicon-user"></i><b class="caret"></b>
<ul class="dropdown-menu">
<li><i class="glyphicon glyphicon-log-out"></i> Sign Out</li>
</ul>
</li>
</ul>
</div><!--/.navbar-collapse -->
</div>
</nav>
<br/>
<div class="container">
Hello first check here you get data or not
public function index(){
$this->data['user'] = $this->user_model->getUser();
$this->load->view('home/header'); /* header.php file which contains bootstrap css */
print_r($this->data);
$this->load->view('home/admin_view', $this->data);
}
If you aren't using a footer, the file admin_view should close the opens tags from 'header' (</div></body></html>) to render well.
Also I suggest you to open the firebug or devtools and check if the table is there or not. If not, try to echo something after loading the 'header' to check if the controller really load the 'admin_view' file.
FYI: the part of the model:
$num_data_returned = $query->num_rows;
if ($num_data_returned < 1) {
echo "No data in database";
exit();
}
Will be never accessed (there is a 'return' before it). Hope it helps!

updating information Mysqli_php

i'm trying to make admin panel for simple website
now i'm trying to update the information
but i don't know why it don't update
on ControlPage
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once("../guest.php");
require_once("../db.php");
global $tf_handle;
$gb = new guest();
$id = 0;
//get id from url
if(isset($_GET['id']))
{
$id = (int)$_GET['id'];
}
$message = $gb->getMessage($id);
if(isset($_POST['submit']))
{
$uid = $_POST['id'];
echo $uid;
$name = $_POST['name'];
echo $name;
$msg = $_POST['message'];
echo $msg;
$update = $gb->Update($id,$name,$msg);
if($update)
{
echo('updated');
}
else
{
echo("not updated");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Guestbook control panel</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/sb-admin.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="css/plugins/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">GuestBook Admin</a>
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li class="dropdown">
<i class="fa fa-user"></i> Ambaleh <b class="caret"></b>
<ul class="dropdown-menu">
<li>
<i class="fa fa-fw fa-gear"></i> Settings
</li>
<li class="divider"></li>
<li>
<i class="fa fa-fw fa-power-off"></i> Log Out
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="active">
<i class="fa fa-fw fa-dashboard"></i> Dashboard
</li>
<li>
<i class="fa fa-fw fa-bar-chart-o"></i>Messages
</li>
<li>
<i class="fa fa-fw fa-bar-chart-o"></i>Logout
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Admin Panel
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> Dashboard
</li>
<li class="active">
<i class="fa fa-table"></i> Messages
</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h2>Update Messages</h2>
<form role="form" action="update.php" method = "post">
<div class="form-group">
<label>Name</label>
<input type="text" name="name" value = '<?php echo $message['name'];?>' class="form-control">
</div>
<div class="form-group">
<label>Message</label>
<textarea name="message" class="form-control" rows="3"><?php echo $message['message'];?></textarea>
</div>
<input type="hidden" name="id" value='<?php echo $id;?>' >
<input type="submit" name="submit" value="save!">
</form>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Morris Charts JavaScript -->
<script src="js/plugins/morris/raphael.min.js"></script>
<script src="js/plugins/morris/morris.min.js"></script>
<script src="js/plugins/morris/morris-data.js"></script>
</body>
</html>
i tried to echo the variables to check
but it already echo & takes the information from the POST request so the problem from another thing
update.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('db.php');
class guest
{
//get all the messages
public function getMessage($id)
{
global $tf_handle;
$querycheck = mysqli_query($tf_handle,"SELECT * FROM `messages` WHERE `id` = $id");
if($querycheck)
{
$message = mysqli_fetch_assoc($querycheck);
return $message;
}
else
{
die('Failed');
}
tinyf_db_close() ;
}
//".$name."
public function Update($id,$name,$message)
{
global $tf_handle;
$query = mysqli_query($tf_handle,"UPDATE `guest`.`messages` SET `name` = ".$name.", `message` = ".$message." WHERE `messages`.`id` = ".$id);
if($query)
{
echo "query Works";
return TRUE;
}
else
{
tinyf_db_close() ;
return False;
}
tinyf_db_close() ;
}
}
?>
i think the problem in this line
$query = mysqli_query($tf_handle,"UPDATE `guest`.`messages` SET `name` = ".$name.", `message` = ".$message." WHERE `messages`.`id` = ".$id);
There may well be other issues but this is the first I see.
text fields in any query need to be wrapped in quotes, single quotes is my preference, so this update wont compile.
$query = mysqli_query($tf_handle,
"UPDATE `guest`.`messages`
SET `name` = ".$name.", `message` = ".$message."
WHERE `messages`.`id` = ".$id);
You can also simplify the building of the query if you remember that double quoted string literals will expand variables automatically
SO Change to
$query = mysqli_query($tf_handle,
"UPDATE `guest`.`messages`
SET `name` = '$name', `message` = '$message' WHERE
`messages`.`id` = $id" );
Also after any mysql calls you should really do something with the actual error message rather than just return false.
if($query) {
echo "query Works";
return true;
} else {
$this->LastError = mysqli_error($tf_handle);
tinyf_db_close() ;
return false;
}
Then in the calling code do
if(isset($_POST['submit']))
{
$uid = $_POST['id']; <-- also change this to
$id = $_POST['id']; <-- this so it matches Update() params
echo $uid;
$name = $_POST['name'];
echo $name;
$msg = $_POST['message'];
echo $msg;
$update = $gb->Update($id,$name,$msg);
if($update) {
echo('updated');
} else {
echo $gb->LastError;
}

When I press submit this form doesn't do anything [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a problem, when I press submit in this form it doesn't do anything.
Its suposed to work because its code from a CMS, its the basic template.
If you need to look at my files i put here my skype to send you team viewer id and pass: javichuskater
You can see the error here: http://javiphp.byethost9.com/
This is the entire code of the index of the CMS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Get Free Bitcoins and Shatoshis Instantly From Our Faucet Online Gana Bitcoins Gratis Instantaneamente Desde Nuestra Faucet">
<meta name="author" content="BTCS4Free.Com">
<meta name="keywords" content="Ganar dinero, Bitcoins Gratis, Bitcoin, RPG Bitcoin, What is Bitcoin, Free Bitcoin, Bitcoin Faucet, Free Coin, Free Cryptocurrency, Fast Bitcoins, FaucetBox Faucet" />
<style>#l3c3{position:fixed!important;position:absolute;top:2px;top:expression((t=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)+"px");left:-2px;width:106%;height:104%;background-color:#FFCE85;opacity:.95;filter:alpha(opacity=95);display:block;padding:20% 0}#l3c3 *{text-align:center;margin:0 auto;display:block;filter:none;font:bold 14px Verdana,Arial,sans-serif;text-decoration:none}#l3c3~*{display:none}</style>
<div id="l3c3"><span>Please enable JavaScript!<br>[ BTCS4Free Webmaster ]</span></div><script>window.document.getElementById("l3c3").parentNode.removeChild(window.document.getElementById("l3c3"));(function(l,m){function n(a){a&&l3c3.nextFunction()}var h=l.document,p=["i","s","u"];n.prototype={rand:function(a){return Math.floor(Math.random()*a)},getElementBy:function(a,b){return a?h.getElementById(a):h.getElementsByTagName(b)},getStyle:function(a){var b=h.defaultView;return b&&b.getComputedStyle?b.getComputedStyle(a,null):a.currentStyle},deferExecution:function(a){setTimeout(a,2E3)},insert:function(a,b){var e=h.createElement("span"),d=h.body,c=d.childNodes.length,g=d.style,f=0,k=0;if("l3c3"==b){e.setAttribute("id",b);g.margin=g.padding=0;g.height="100%";for(c=this.rand(c);f<c;f++)1==d.childNodes[f].nodeType&&(k=Math.max(k,parseFloat(this.getStyle(d.childNodes[f]).zIndex)||0));k&&(e.style.zIndex=k+1);c++}e.innerHTML=a;d.insertBefore(e,d.childNodes[c-1])},displayMessage:function(a){var b=this;a="abisuq".charAt(b.rand(5));b.insert("<"+a+'><div class="well text-center" style="width:50%"><b>AD BLOCK DETECTED<br /><br />Please disable it for this site and reload the page.</b><br />BTCS4Free Faucet depends on the revenue from displaying adverts.</div> [ BTCS4Free Webmaster ]'+("</"+a+">"),"l3c3");h.addEventListener&&b.deferExecution(function(){b.getElementBy("l3c3").addEventListener("DOMNodeRemoved",function(){b.displayMessage()},!1)})},i:function(){for(var a="SponsorsAds,adBlock01,ads-300-250,bott_ad2,dlads,ifmSocAd,toptextad,ad,ads,adsense".split(","),b=a.length,e="",d=this,c=0,g="abisuq".charAt(d.rand(5));c<b;c++)d.getElementBy(a[c])||(e+="<"+g+' id="'+a[c]+'"></'+g+">");d.insert(e);d.deferExecution(function(){for(c=0;c<b;c++)if(null==d.getElementBy(a[c]).offsetParent||"none"==d.getStyle(d.getElementBy(a[c])).display)return d.displayMessage("#"+a[c]+"("+c+")");d.nextFunction()})},s:function(){var a={'pagead2.googlesyndic':'google_ad_client','js.adscale.de/getads':'adscale_slot_id','get.mirando.de/miran':'adPlaceId'},b=this,e=b.getElementBy(0,"script"),d=e.length-1,c,g,f,k;h.write=null;for(h.writeln=null;0<=d;--d)if(c=e[d].src.substr(7,20),a[c]!==m){f=h.createElement("script");f.type="text/javascript";f.src=e[d].src;g=a[c];l[g]=m;f.onload=f.onreadystatechange=function(){k=this;l[g]!==m||k.readyState&&"loaded"!==k.readyState&&"complete"!==k.readyState||(l[g]=f.onload=f.onreadystatechange=null,e[0].parentNode.removeChild(f))};e[0].parentNode.insertBefore(f,e[0]);b.deferExecution(function(){if(l[g]===m)return b.displayMessage(f.src);b.nextFunction()});return}b.nextFunction()},u:function(){var a="-ad1.,/ad-choices-,/ads620x60/ad,/adstop728.,/adtest/ad,/custom/ads,/layer-advert-,/public/ads/ad,/pubmatic_,/728x90b/ad".split(","),b=this,e=b.getElementBy(0,"img"),d,c;e[0]!==m&&e[0].src!==m&&(d=new Image,d.onload=function(){c=this;c.onload=null;c.onerror=function(){p=null;b.displayMessage(c.src)};c.src=e[0].src+"#"+a.join("")},d.src=e[0].src);b.deferExecution(function(){b.nextFunction()})},nextFunction:function(){var a=p[0];a!==m&&(p.shift(),this[a]())}};l.l3c3=l3c3=new n;h.addEventListener?l.addEventListener("load",n,!1):l.attachEvent("onload",n)})(window);</script>
<title>BTCS4Free - FreeBitcoins Instantly!</title>
<!-- Bootstrap Core CSS - Uses Bootswatch Flatly Theme: http://bootswatch.com/flatly/ -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/freelancer.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top" class="index">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#page-top">BTCS4Free.Com</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
</li>
<li class="page-scroll">
Faucet
</li>
<li class="page-scroll">
About
</li>
<li class="page-scroll">
Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<!-- Header -->
<header>
<div class="container">
<div class="row">
<div class="col-lg-12">
<img class="img-responsive" src="img/profile.png" alt="">
<div class="intro-text">
<span class="name">BTCS4Freep</span>
<hr class="star-light">
<span class="skills">Free BitCoins instantly!</span>
</div>
</div>
</div>
</div>
</header>
<!-- Portfolio Grid Section -->
<section id="faucet">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Faucet</h2>
<hr class="star-primary">
<div id="left">
<ul>
<?php foreach($data["user_pages"] as $page): ?>
<li><?php echo $page["name"]; ?></li>
<?php endforeach; ?>
</ul>
<?php echo $data["custom_left_ad_slot"]; ?>
<p>Possible rewards: <?php echo $data["rewards"]; ?></p>
</div>
<div id="center">
<h1><?php echo $data["name"]; ?></h1>
<h2><?php echo $data["short"]; ?></h2>
<p>Balance: <?php echo $data["balance"]." ".$data["unit"]; ?></p>
<?php if($data["error"]) echo $data["error"]; ?>
<?php switch($data["page"]):
case "disabled": ?>
FAUCET DISABLED. Go to admin page and fill all required data!
<?php break; case "paid":
echo $data["paid"];
break; case "eligible": ?>
<form method="POST" role="form">
<div>
<?php if(!$data["captcha_valid"]): ?>
<p class="alert alert-danger" role="alert">Invalid Captcha!</p>
<?php endif; ?>
</div>
<div>
<label for="address">Your address:</label> <input type="text" name="address" class="form-control" value="<?php echo $data["address"]; ?>">
</div>
<div>
<?php echo $data["captcha"]; ?>
<div class="text-center">
<?php
if (count($data['captcha_info']['available']) > 1) {
foreach ($data['captcha_info']['available'] as $c) {
if ($c == $data['captcha_info']['selected']) {
echo '<b>' .$c. '</b> ';
} else {
echo ''.$c.' ';
}
}
}
?>
</div>
</div>
<div>
<input type="submit" class="btn btn-primary btn-lg" value="Get reward!">
</div>
</form>
<?php break; case "visit_later": ?>
<p>You have to wait <?php echo $data["time_left"]; ?></p>
<?php break; case "user_page": ?>
<?php echo $data["user_page"]["html"]; ?>
<?php break; endswitch; ?>
</div>
<div id="right">
<?php echo $data["custom_right_ad_slot"]; ?>
<?php if($data["referral"]): ?>
<p>
Referral commission: <?php echo $data["referral"]; ?>%<br>
Reflink:<br>
<code><?php echo $data["reflink"]; ?></code>
</p>
<?php endif; ?>
</div>
Thanks for your help and time!
i have checked the link you have provided http://javiphp.byethost9.com/. it fires an ajax call to 'http://javiphp.byethost9.com/mail/contact_me.php' and return the response as 'No arguments Provided!'.
Ajax call is made by this script file <script src="js/contact_me.js"></script>
I think, it is stopping further proccess.

Displaying different include file based on logged in status

I'm trying to include a different navigation menu for users that are logged in but seem to be having trouble. I'm currently setting a session when a user successfully authenticates, that session then sets a session variable so we know if the user is logged in or logged out.
If they are logged in, they should see the logged in menu, otherwise they should just see the logged out menu. For some reason i cannot get this to work through checking if the user is logged in - not sure what i'm doing wrong.
index.php
<?php
require_once("inc/config.php");
require(ROOT_PATH . "inc/database.php");
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Property Rental</title>
<!-- CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/responsive.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<header role="banner" id="top" class="navbar navbar-static-top bs-docs-nav">
<div class="container">
<div class="navbar-header">
<button data-target=".bs-navbar-collapse" data-toggle="collapse" type="button" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav role="navigation" class="collapse navbar-collapse bs-navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">
Menu Item 1
</li>
<li>
Menu Item 2
</li>
<li>
Menu Item 3
</li>
<li>
Menu Item 4
</li>
<li>
Menu Item 5
</li>
<?php
if ( $_SESSION['loggedin'] == true) {
include("inc/logged.php");
} else {
include("inc/loggedOut.php");
}
print_r($_SESSION);
?>
</ul>
</nav>
</div>
</header>
<div class="container">
<h1>Hello, world!</h1>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/core.js"></script>
</body>
</html>
users.database.php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
try {
$result = $db->prepare("SELECT username, pass FROM user_info WHERE username = :user AND BINARY pass = :pass");
$result->bindParam(':user', $username);
$result->bindParam(':pass', $password);
$result->execute();
$rows = $result->fetch(PDO::FETCH_NUM);
}
catch (Exception $e) {
echo "Could not retrieve data from database";
exit();
}
if ($password = $rows) {
session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['loggedin'] = true;
} else {
if (isset($_POST['login'])) {
echo "Username or password incorrect (passwords are case sensitive)";
}
}
?>
logged.php
<li class="login-register pull-right">
<ul>
<li class="login pull-left">
My Account
<div class="login-box">
<div class="login-box-inner">
Logout
</div>
</form>
</div>
</li>
</ul>
</li>
loggedOut.php
<li class="login-register pull-right">
<ul>
<li class="login pull-left">
Login
LOGOUT
<div class="login-box">
<div class="login-box-inner">
<div class="up-arrow"></div>
<form role="form" method="post">
<div class="form-group">
<label>Username or Email</label>
<input type="text" name="username">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password">
</div>
<?php require(ROOT_PATH . "inc/users.database.php"); ?>
<div class="form-group">
<div class="row">
<div class="col-xs-6">
<label class="remember-me">
<input type="checkbox" name="remember"> Remember me
</label>
</div>
<div class="col-xs-6">
<button type="submit" name="login" class="btn btn-small btn-primary pull-right">Login</button>
</div>
</div>
</div>
</form>
</div>
</form>
</div>
</li>
<span class="slash">/</span>
<li class="pull-right">
Register
</li>
</ul>
</li>
$loggedin is not being set in your index.php file.
Replace your if condition with this:
if ($_SESSION['loggedin'] == true) {
You can also use this which has the exact same meaning...
if ( $_SESSION['loggedin'] ) {
With the above code, you are going to need to start a session on that page with session_start();
If you are using javascript to go back in the history when a user logs in, change it to this...
<script>
window.location.href = document.referrer;
</script>
NOTE: This will only go back one page in the history.

Categories