Is it possible to get 'Session User" to display - php

Hi there I'm trying to get a user who comments and is logged in to their account for their 'Login Name' to display when they comment currenlty when a user wants to comment it asks for their name and their comment. Is it possible to display their name getting it from the session to display it? Thanks!
http://puu.sh/cByNU/697e58cdf6.jpg http://puu.sh/cByNU/697e58cdf6.jpg
On the image I'm logged in as 'Testing' is it possible to remove the field 'Name' and when they post a comment it will get their name where the search box is (testing).
Thanks!
My CODE:
<?php
session_start();
include "../includes/config.php";
include "function.php";
include ('../includes/header.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Honda</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
<!--start lightbox -->
<link rel="stylesheet" type="text/css" href="../css/jquery.lightbox.css">
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.lightbox.js"></script>
<script>
// Initiate Lightbox
$(function() {
$('.gallery1 a').lightbox();
});
</script>
</head>
<body>
<!--start header-->
<div class="h_bg">
<div class="wrap">
<div class="wrapper">
<div class="header">
<div class="logo">
<img src="../images/logo.png">
</div>
<div class="cssmenu">
<ul>
<li><span>Home</span></li>
<li><span>About</span></li>
<li class="active" class="has-sub"><span>Gallery</span>
</li>
<li class="last"><span>Contact</span></li>
<div class="clear"></div>
<form action="search.php" method="GET">
<div class="search">
<h2>search</h2>
<form>
<input type="text" name="query" placeholder="Enter Your search..." />
<input type="submit" value="">
</form>
</div>
</form>
<div class="search1">
<form action="" method="POST">
<br>
<h2>Welcome, <?=$_SESSION['sess_user'];?>!</h2><br><br>
<div class="pw">
<h3>Change details</h3>
</div>
<br><br>
<h2>Logout</h2>
</form>
</div>
</div>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start content -->
<div class="content_bg">
<div class="wrap">
<div class="wrapper">
<div class="main">
<div class="ser-main">
<h2 class="style">Gallery of honda</h2>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic1.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic2.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic3.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic4.jpg" alt="">
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="footer_bg">
<div class="wrap">
<div class="wrapper">
<div class="footer">
<div class="search69">
<?php
if(isset($_POST['submit'])
&& !empty($_POST['name'])
&& !empty($_POST['comment']) ){
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
$insert=mysql_query("INSERT INTO comment (name,comment) VALUES ('$name','$comment') ");
echo "<meta HTTP-EQUIV='REFRESH' content='0; url=service.php'>";
}
else
{
echo "";
}
?>
<form class="comments" action="service.php" method="POST">
<h2>Name: </h2><br><input type="text" name="name" required/><br><br>
<h2>Comment:</h2><textarea name="comment" rows="10" cols="50" required></textarea><br><br><br>
<input type="submit" name="submit" value="Comment">
</form>
<?php
$getquery=mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$date=$rows['date'];
$name=$rows['name'];
$comment=$rows['comment'];
echo '<h2><hr size="1"/><br><font color="green">' . $name . '</font><h2><br/>' . '<br/>' . $comment . '<br/><br><font color="red">' . $date. '</font><br/>' . '<hr size="1"/>'
;}
?>
</div>
<div class="copy">
<p class="w3-link">2014 </p>
Privacy & Policy
</div>
<div class="f_nav">
<ul>
<li>Skype</li>
<li>Linked in</li>
<li>Twitter</li>
<li>Facebook</li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</body>
</html>
(ALL MY CODE ON THAT PAGE)

UPDATE:
The guys here will kill me, because now i am just edited your code, and not rewrite to mysqli or PDO, but as i saw, you stuck, so i've just updated, bacause i do not want to confuse with that too. I do some modifications, check my comments about that. (Moved the block of insertion to the top of file, add an error message, remove unnecesarry variables, rename the rows variable to row, etc...)
<?php
session_start();
include "../includes/config.php";
include "function.php";
include ('../includes/header.php');
//Set an empty errorMsg because later we will check it.
$errorMsg = '';
//If everything is set, or the SESSION["sess_user"] not empty.
//I moved this whole thing here, because if there are no output, we can
//redirect user from PHP, and do not need to use META REFREHS...
if (isset($_POST['submit']) && !empty($_POST['comment']) && (!empty($_POST["name"]) || !empty($_SESSION["sess_user"]))) {
if (!empty($_SESSION["sess_user"])) {
$name = $_SESSION["sess_user"];
} else {
$name = $_POST["name"];
}
//$comment = $_POST['comment']; //Use $_POST["comment"] directly
//$submit = $_POST['submit']; //Do not use it anywhere
$insert = mysql_query("INSERT INTO comment (name,comment) VALUES ('" . mysql_real_escape_string($name) . "','" . mysql_real_escape_string($_POST["comment"]) . "')");
Header("Location: service.php");
} else {
$errorMsg = "You need to fill all the fields.";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Honda</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
<!--start lightbox -->
<link rel="stylesheet" type="text/css" href="../css/jquery.lightbox.css">
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.lightbox.js"></script>
<script>
// Initiate Lightbox
$(function() {
$('.gallery1 a').lightbox();
});
</script>
</head>
<body>
<!--start header-->
<div class="h_bg">
<div class="wrap">
<div class="wrapper">
<div class="header">
<div class="logo">
<img src="../images/logo.png">
</div>
<div class="cssmenu">
<ul>
<li><span>Home</span></li>
<li><span>About</span></li>
<li class="active" class="has-sub"><span>Gallery</span>
</li>
<li class="last"><span>Contact</span></li>
<div class="clear"></div>
<form action="search.php" method="GET">
<div class="search">
<h2>search</h2>
<form>
<input type="text" name="query" placeholder="Enter Your search..." />
<input type="submit" value="">
</form>
</div>
</form>
<div class="search1">
<form action="" method="POST">
<br>
<h2>Welcome, <?= $_SESSION['sess_user']; ?>!</h2><br><br>
<div class="pw">
<h3>Change details</h3>
</div>
<br><br>
<h2>Logout</h2>
</form>
</div>
</div>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start content -->
<div class="content_bg">
<div class="wrap">
<div class="wrapper">
<div class="main">
<div class="ser-main">
<h2 class="style">Gallery of honda</h2>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic1.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic2.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic3.jpg" alt="">
</div>
</div>
<div class="ser-grid-list img_style">
<div class="gallery1">
<img src="../images/ser_pic4.jpg" alt="">
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="footer_bg">
<div class="wrap">
<div class="wrapper">
<div class="footer">
<div class="search69">
<?php
//Added here the errorMsg
if (!empty($errorMsg)) {
?>
<div class="error"><?php echo $errorMsg; ?></div>
<?php
}
?>
<form class="comments" action="service.php" method="POST">
<?php
if (!empty($_SESSION['sess_user'])) {
//If user logged in, use the name of it
?>
<h2>Name: </h2><br><?php echo $_SESSION['sess_user']; ?>
<br><br>
<?php
} else {
//Else, ask it
?>
<h2>Name: </h2><br><input type="text" name="name" required/><br><br>
<?php
}
?>
<h2>Comment:</h2><textarea name="comment" rows="10" cols="50" required></textarea><br><br><br>
<input type="submit" name="submit" value="Comment">
</form>
<?php
$getquery = mysql_query("SELECT * FROM comment ORDER BY id DESC");
//This is one row, not rows
while ($row = mysql_fetch_assoc($getquery)) {
/*
* These are not necessary
$id = $rows['id'];
$date = $rows['date'];
$name = $rows['name'];
$comment = $rows['comment'];
*/
echo '<h2><hr size="1"/><br><font color="green">' . $row['name'] . '</font><h2><br/>' . '<br/>' . $row['comment'] . '<br/><br><font color="red">' . $row['date'] . '</font><br/>' . '<hr size="1"/>'
;
}
?>
</div>
<div class="copy">
<p class="w3-link">2014 </p>
Privacy & Policy
</div>
<div class="f_nav">
<ul>
<li>Skype</li>
<li>Linked in</li>
<li>Twitter</li>
<li>Facebook</li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</body>
</html>
NOTE: Do not use mysql functions since they are deprecated. use mysqli or PDO functions instead.
Acoid for sql injections, so escape your data!

If i got it well, you want the form to automatically gets the name of a logged user. You should:
<?php $username = isset($_SESSION['sess_user']) ? $_SESSION['sess_user'] : "";?>
To store the username or "" into $username, depending on whether user is authentified or not. Then in your input line within the form:
<h2>Name: </h2><br><input type="text" name="name" value="<?php echo $username; ?>" required/><br><br>

Related

How to create a edit profile page for users with PHP?

I've created a page but I can´t put the Save button working and regardless of the user I enter with, it appears the same user information for them all.
I think it's a loop problem but I'm not sure what it is.
<?php
require_once('LoginConfig.php');
session_start();
if(isset($_SESSION["email"])){
$user_check = $_SESSION["email"];
$result = $connect->prepare("SELECT * FROM users WHERE user_email = :usercheck");
$result->execute(array(":usercheck"=>$user_check));
$row = $result->fetch(PDO::FETCH_ASSOC);
}else
{
header("location:UsersLogin.php");
}
?>
<!DOCTYPE html>
<html lang="PT-pt">
<head>
<title> Editar Perfil - JamJam </title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:700, 600,500,400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/style-menu.css">
<link rel="stylesheet" type="text/css" href="assets/css/style-articlelist2.css">
<script src="https://kit.fontawesome.com/8a368d3752.js"></script>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="assets/js/main.js"></script>
<style>
</style>
</head>
<body>
<div class="header">
<div class="logo">
<i style='font-size:24px' class='fas'></i>
<span style='font-size:24px'>JamJam</span>
</div>
<span></span>
</div>
<div class="side-nav">
<div class="logo">
<i style='font-size:24px; color:rgb(0,255,0)' class='fas'></i>
<span style='font-size:24px'>JamJam</span>
</div>
<nav>
<ul>
<li>
<a href="UsersMenu.php">
<span><i style='color:rgb(0,255,0)' class="fas fa-home"></i></span>
<span>Página Inicial</span>
</a>
</li>
<li class="active">
<a href="UsersProfile.php">
<span><i style='color:rgb(0,255,0)' class="fa fa-user"></i></span>
<span>Perfil</span>
</a>
</li>
<li>
<a href="UsersArticleList.php">
<span><i style='color:rgb(0,255,0)' style='font-size:16px' class='fas'>&#xf001</i></span>
<span>Músicas</span>
</a>
</li>
<li>
<a href="Logout.php">
<span><i style='color:rgb(0,255,0)' class="fas fa-sign-out-alt"></i></span>
<span>Logout</span>
</a>
</li>
</ul>
</nav>
</div>
<div class="main-content">
<div class="title">
Editar Perfil
</div>
<div class="main">
<div class="widget" style="lex-basis: 98%; height: 750px;">
<?php
if(isset($_SESSION["email"])){
$result = $connect->prepare("SELECT user_id, user_name, user_bio, user_local, user_image FROM users");
$result->bindParam(':userid', $id);
$result->execute();
$row = $result->fetch()
?>
<form style="text-align: left; margin: 15px; " action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input $id="user_id" name="user_id" type="hidden" value= "<?php echo $row['user_id']; ?>">
<div >
<label for="username">Nome:</label><br>
<input type="text" name="username" value="<?php echo $row['user_name']; ?>">
</div>
<div>
<label for="bio">Bio:</label>
<br>
<textarea type="text" class="textarea" name="bio" rows ="4"><?php echo $row['user_bio']; ?></textarea>
</div>
<div>
<label for="local">Sítio onde vive:</label><br>
<input type="text" name="local" value="<?php echo $row['user_local']; ?>">
</div>
<div>
<label for="image">Foto de perfil atual:</label><br>
<img src="<?php echo 'images/' . $row['user_image']; ?>">
</div>
<div>
<br> <form action="upload.php" method="post" enctype="multipart/form-data">
<lable for="image">Selecionar nova foto de perfil:</lable><br>
<input type="file" name="fileToUpload" id="fileToUpload">
</form>
</div>
<div style="text-align: left; margin: 10px;" class="box">
<button style="float: left;" class="saveButton" type="submit">Guardar</button>
<a style="float: right;" class="cancelButton" href="UsersProfile.php">Cancelar</a>
</div>
</form>
<?php
}
?>
</div>
</div>
</body>
</html>

The footer of my website's homepage isn't coming

I have been trying to make a website. It is an online shopping website.
This is my code-
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Books And Beyond</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Bootstrap styles open source -->
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" crossorigin="anonymus">
<!-- Customize styles -->
<link href="style.css" rel="stylesheet"/>
<!-- font awesome styles open source -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" crossorigin="anonymus">
<!-- Favicons -->
<link rel="shortcut icon" href="/favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style
type="text/css">
<!--
body {
background-image: url(assets/img/background.jpg);
}
-->
</style></head>
<body>
<!--
Upper Header Section
-->
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="topNav">
<div class="container">
<div class="alignR">
<?php if (isset($_SESSION['email'])) { echo $_SESSION['email']; } else { ?>
<ul class="nav pull-right">
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#"><span class="icon-lock"></span> Login <b class="caret"></b></a>
<div class="dropdown-menu">
<form class="form-horizontal loginFrm" action="checkuser.php" method="post">
<div class="control-group">
<input name="email" type="text" class="span2" id="email" placeholder="Email">
</div>
<div class="control-group">
<input name="password" type="password" class="span2" id="password" placeholder="Password">
</div>
<div class="control-group">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button name="login" type="submit" class="shopBtn btn-block">Sign in</button>
</div>
</form>
</div>
</li>
</ul>
<?php } ?>
<?php if (isset($_SESSION['email'])) { ?>
Logout
<?php } else { ?>
<span class="icon-edit"></span> Register
<?php }?>
</div>
</div>
</div>
</div>
<!--
Lower Header Section
-->
<div class="container">
<div id="gototop"> </div>
<header id="header">
<div class="row">
<div class="span4">
<h1>
<a class="logo" href="index.php"><span>Books And Beyond</span>
<img src="assets/img/logo1.jpg" alt="" width="218" height="94"> </a> </h1>
</div>
</div>
</header>
<!--
Navigation Bar Section
-->
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<div class="nav-collapse">
<ul class="nav">
<li class="active">Home</li>
<li class="">About</li>
<li class="">Bargain Books</li>
<li class="">New Releases</li>
<li class="">Bestsellers</li>
<li class="">Contact Us</li>
</ul>
<ul class="nav pull-right">
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span12">
<img src="assets/img/banner.jpg"/>
<hr class="soften"/>
</div>
</div>
<!--Body Section
-->
<div class="row">
<div id="sidebar" class="span3">
<div class="well well-small">
<h3> Category </h3>
<ul class="nav nav-list">
<li><span class="icon-chevron-right"></span>Fiction</li>
<li><span class="icon-chevron-right"></span>Non-Fiction</li>
<li><span class="icon-chevron-right"></span>Young Adult</li>
<li><span class="icon-chevron-right"></span>Children's</li>
<li><span class="icon-chevron-right"></span>Travel</li>
<li><span class="icon-chevron-right"></span>Education</li>
<li style="border:0"> </li>
</ul>
</div>
<!--<div class="well well-small alert alert-warning cntr">
<h2>50% Discount</h2>
<p>
only valid for online order. <br><br><a class="defaultBtn" href="#">Click here </a>
</p>
</div>-->
<!-- <div class="well well-small" ><img src="assets/img/paypal.jpg" alt="payment method paypal"></div>-->
<!--<a class="shopBtn btn-block" href="#">Upcoming products <br><small>Click to view</small></a>-->
<ul class="nav nav-list promowrapper">
<?php
/* require_once('dbconnect.php'); */
$result = mysql_query("SELECT * from product WHERE brand='accessories'");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
$price=$row["productprice"];
$productimage=$row["productimage"];
?>
<li>
<div class="thumbnail">
<img width="200" height="80" src="getImage.php?intproductid=<?php print $intproductid;?>" />
<div class="caption">
<table width="250" border="0">
<tr>
<td align="left" valign="middle"><form action="product_detail.php" method="post" name="form2" id="form2">
<label>
<input type="hidden" name="intproductid2" value="<?php echo $intproductid; ?>" />
<input name="Submit2" type="submit" class="shopBtn" value="View" />
</label>
</form></td>
<td align="right" valign="middle"><h4> <span class="pull-right"><?php echo $price; ?>.00</span></h4></td>
</tr>
</table>
</div>
</div>
</li>
<li style="border:0"> </li>
<?php } ?>
</ul>
</div>
<div class="span9">
<!--
New Products
-->
<div class="well well-small">
<h3>New Products </h3>
<hr class="soften"/>
<div class="row-fluid">
<div id="newProductcar" class="carousel slide">
<div class="">
<div class="item active">
<ul class="thumbnails">
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='bousni' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='hela couture' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='zey' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='AL-JUMAIRA' LIMIT 1");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
//$productimage=$row["productimage"];
?>
<li class="span3">
<div class="thumbnail">
<img width="200" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="well well-small">
<div class="span8">
<div class="row-fluid">
<h3>Features Products </h3>
<hr class="soften"/>
<ul class="thumbnails">
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='roza' LIMIT 3");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
$productname=$row["productname"];
$brand=$row["brand"];
$price=$row["productprice"];
$productimage=$row["productimage"];
?>
<li class="span4">
<div class="thumbnail">
<img width="250" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
<div class="caption cntr">
<p style="color:#990033"><?php echo $productname; ?></p>
<p><?php echo $brand; ?></p>
<p><strong>SAR <?php echo $price; ?>.00</strong></p>
<div class="btn-group">
<form id="form2" name="form2" method="post" action="product_detail.php">
<label>
<input type="hidden" name="intproductid2" value="<?php echo $intproductid; ?>" />
<input name="Submit2" type="submit" class="shopBtn" value="View" />
<input name="Submit2" type="submit" class="defaultBtn" value="Add to cart" />
</label>
</form>
</div>
<br class="clr">
</div>
</div>
</li>
<?php } ?>
</ul>
<hr class="soften"/>
<ul class="thumbnails">
<?php
require_once('dbconnect.php');
$result = mysql_query("SELECT * from product WHERE brand='haya' LIMIT 3");
while ($row = mysql_fetch_array($result))
{
$intproductid=$row["id"];
$productname=$row["productname"];
$brand=$row["brand"];
$price=$row["productprice"];
$productimage=$row["productimage"];
?>
<li class="span4">
<div class="thumbnail">
<img width="250" height="120" src="getImage.php?intproductid=<?php print $intproductid;?>" />
<div class="caption cntr">
<p style="color:#990033"><?php echo $productname; ?></p>
<p><?php echo $brand; ?></p>
<p><strong>SAR <?php echo $price; ?>.00</strong></p>
<div class="btn-group">
<form id="form2" name="form2" method="post" action="product_detail.php">
<label>
<input type="hidden" name="intproductid2" value="<?php echo $intproductid; ?>" />
<input name="Submit2" type="submit" class="shopBtn" value="View" />
<input name="Submit2" type="submit" class="defaultBtn" value="Add to cart" />
</label>
</form>
</div>
<br class="clr">
</div>
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
<div class="row">
</div>
</div>
</div></div></div>
<!--
Footer
-->
<footer class="footer" style="float: bottom;">
<div class="row-fluid">
<div class="span3">
<h5>ORDER SUPPORT</h5>
Store pickup<br>
Return and Refund<br>
</div>
<div class="span3">
<h5>PRODUCT SUPPORT</h5>
FAQs<br>
Inquiry<br>
</div>
<div class="span3">
<h5>COOPORATIVE INFO</h5>
Terms and Condition <br>
Contact us<br>
</div>
<div class="span3">
<h5>GET CONNECTED</h5>
About us <br>
Create Account<br>
</div>
</div>
</footer>
</div><!-- /container -->
<div class="copyright">
<div class="container">
<p class="pull-right"> </p>
<span>Copyright 2019, Fatimatuz Johura - s201403034- Jeddah (Ladies Branch);<br> Books And Beyond</span>
</div>
</div>
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.easing-1.3.min.js"></script>
<script src="assets/js/jquery.scrollTo-1.4.3.1-min.js"></script>
<script src="assets/js/shop.js"></script>
</body>
</html>
The 'New Products' and the footer section is not coming and I cant figure out why. I dont have a webhost yet so I am using localhost for now. I have tried editing the code but whatever I do, it does not seem to work. If anyone can help, I would really appreciate it. Thank you.
On line 152 (new products is on line ~ 185[ish])
/* require_once('dbconnect.php'); */
$result = mysql_query("SELECT * from product WHERE brand='accessories'");
As I said in the comments you use this require_once('dbconnect.php'); multiple times when it should be only once at the top of your file.
The above code is the first occurrence I could find, and as it's commented out, that query is going to bomb out on you. Execution happens top to bottom and the first uncommitted occurrence of that is line 196[ish], which is way to late for that first query.
Also as I said in the comments
Try turning on Error reporting - error_reporting(-1); and ini_set('display_errors', '1'); put those right after the <?php tag
You can save yourself, and us a lot of time that way.
So in Summery,
Remove all of these require_once('dbconnect.php'); and then add just one after the opening <?php tag.
PS you can easily test this, by just commenting that first query out, or by uncommenting that first require_once.

HTTP Error 500 PHP

I am getting an HTTP Error 500 on my website. The PHP code checker doesn't see anything suspicious.
I think it's caused by PDO but I'm not sure because when I remove all the PHP code it still gives me the same error.
Here's my code:
Index.php:
<?php
include_once('includes/db_connect.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable="no>
<!-- Custom CSS -->
<link rel="stylesheet" href="css/custom.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css" />
<!-- Optional theme (flatly) -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootswatch/latest/flatly/bootstrap.min.css" />
<!-- Font awesome -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/contact.css" rel="stylesheet">
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="js/contact.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/latest/js/bootstrap.min.js"></script>
<title><?php
foreach($dbh->query('SELECT * FROM page_info') as $row) {
echo $row['title'];
}
?></title>
</head>
<body>
<div class="banner">
<div class="name"><?php
foreach ($dbh->query('SELECT * FROM page_info') as $row) {
echo $row[“name”];
}
?></div>
</div>
<div class="about">
<div class="about-container">
<div class="about-main-text">
<h1>About me:</h1>
<?php
foreach ($dbh->query('SELECT * FROM about') as $row) {
echo '
<span>'.$row["text"].'</span>
';
}
?>
</div>
</div>
</div>
<div class="projects">
<div class="projects-container">
<div class="projects-main-text">
<h1>My projects:</h1>
</div>
<div class="row">
<?php
foreach($dbh->query('SELECT * FROM projects') as $row) {
echo '
<div class="col-md-4 nopadding">
<div class="project-box">
<img src="data:image/jpeg;base64,'.base64_encode( $row['image'] ).'" alt="Project Image">
<h1>'.$row["name"].'</h1>
<p>'.$row["desc"].'</p>
</div>
</div>
';
}
?>
</div>
</div>
</div>
<div class="contact">
<div class="contact-container">
<div class="contact-main-text">
<h1>Contact me:</h1>
</div>
<div class="row">
<form action="contact/send.php" method="post" style="float: left;">
<div class="field name-box">
<input type="text" id="name" name="name" placeholder="Who Are You?"/>
<label for="name">Name</label>
<span class="ss-icon">check</span>
</div>
<div class="field email-box">
<input type="text" id="email" name="email" placeholder="name#email.com"/>
<label for="email">Email</label>
<span class="ss-icon">check</span>
</div>
<div class="field msg-box">
<textarea id="msg" rows="4" placeholder="Your message goes here..."/></textarea>
<label for="msg">Msg</label>
<span class="ss-icon">check</span>
</div>
<input class="button" type="submit" value="Send" />
</form>
</div>
</div>
</div>
<div class="footer">
<span class="copyright">
© <?php
foreach ($dbh->query('SELECT * FROM page_info') as $row) {
echo $row['copyright'];
}
echo ' ' . date("Y");
?> - All rights reserved
</span>
</div>
</body>
</html>
And here is db_connect.php:
<?php
$uname = ‘rik_root’;
$upass = ‘*********’;
$dbh = new PDO('mysql:host=localhost;dbname=nijdeken’, $uname, $upass);
?>
I hope someone can help me. Thanks in advance!
Don't use a word processor to edit your code:
$uname = ‘rik_root’;
^--------^
those are not valid php quote characters, and are probably killing your code with a fatal parse error:
$dbh = new PDO('mysql:host=localhost;dbname=nijdeken’, $uname, $upass);
^--start of string ^--NOT an end-of-string

PHP using sqlite3 with forms

I am new to php and sqlite and wanted to make a form that inserts everything there into the database.
This is my contact.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>G6 Mall | Contact</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.5.2.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Terminal_Dosis_300.font.js"></script>
<script type="text/javascript" src="js/atooltip.jquery.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<style type="text/css">.bg {behavior:url("js/PIE.htc")}</style>
<![endif]-->
</head>
<body id="page6">
<div class="body1">
<div class="body2">
<div class="body3">
<div class="main">
<!-- header -->
<header>
<div class="wrapper">
<h1></h1>
<form id="search" action="#" method="post">
<div>
<input type="submit" class="submit" value="">
<input class="input" type="text" value="Site Search" onBlur="if(this.value=='') this.value='Site Search'" onFocus="if(this.value =='Site Search' ) this.value=''">
</div>
</form>
<nav>
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Directory</li>
<li>News</li>
<li id="active" class="end">Contact</li>
</ul>
</nav>
</div>
</header>
<!-- / header-->
<!-- content -->
<section id="content">
<div class="wrapper">
<h2>General Enquiry Form</h2>
<form id="FeedbackForm" action="post.php" method="post">
<div>
<div class="wrapper"> <span>Name:</span>
<input type="text" class="input" name="NAME">
</div>
<div class="wrapper"> <span>Contact:</span>
<input type="text" class="input" name="CONTACT">
</div>
<div class="wrapper"> <span>E-mail:</span>
<input type="text" class="input" name="EMAIL">
</div>
<div class="textarea_box"> <span>Message: (50char)</span>
<textarea name="COMMENT" cols="1" rows="1"></textarea>
</div>
<input type="submit" name="update" value="update">
<!--<span> </span> Clear Send </div>-->
</form>
</div>
</section>
</div>
</div>
</div>
</div>
<div class="body4">
<div class="main">
<section id="content2">
<div class="wrapper">
<div style="text-align: center;">
<h2>Where are we located at? </h2>
<strong>Lot-6 G6 Street, Wollongong, 6666 NSW</strong>
<p><!--spacing between the headers-->
</div>
<div class="line3 wrapper">
<article class="col2">
<h2>G6 Card privileges+ </h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Email: </strong> </span>
+614 1234 6666<br>
g6card#g6.com </div>
</article>
<article class="col2">
<h2>Customer Service Centre </h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Email: </strong> </span>
+614 1234 5555<br>
custserv#g6.com </div>
</article>
<article class="col2">
<h2>Advertisement & Promotion</h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Fax No:<br>
Email: </strong> </span>
+614 1234 7777<br>
+614 1234 1212<br>
adsPromo#g6.com </div>
</article>
<article class="col2">
<h2>Leasing</h2>
<div class="pad"> <span class="col3"> <strong>
Telephone:<br>
Fax No:<br>
Email: </strong> </span>
+614 7728 8878<br>
+614 7726 8869<br>
leasing#g6.com </div>
</article></div>
</div>
</section>
</div>
</div>
<!-- / content -->
<div class="main">
<!-- footer -->
<footer>
<div class="wrapper"> <span class="left"> Copyright © G6. All Rights Reserved<br>
Design by LM-02</a><br>
</span>
<ul id="icons">
Connect with us: <br>
<li><img src="images/icon1.png" alt=""></li>
<li><img src="images/icon4.png" alt=""></li>
</ul>
</div>
<!-- {%FOOTER_LINK} -->
</footer>
<!-- / footer -->
</div>
</body>
</html>
Then i made a post.php and put this code down
<?php
$NAME = sqlite_escape_string($_POST['NAME']);
$CONTACT = sqlite_escape_string($_POST['CONTACT']);
$EMAIL = sqlite_escape_string($_POST['EMAIL']);
$COMMENT = sqlite_escape_string($_POST['COMMENT']);
class MyDB extends SQLite3
{
function __construct()
{
$this->open('final_mall_management_system.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}
$sql =<<<EOF
INSERT INTO Enquiry (Name,Contact,Email,Comment)
VALUES ( '$NAME', '$CONTACT', '$EMAIL', '$COMMENT' );
EOF;
$ret = $db->exec($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {
echo "Records created successfully\n";
}
$db->close();
?>
When I entered the data in the form and click the submit it doesn't work I get this instead
open('final_mall_management_system.db'); } } $db = new MyDB(); if(!$db){ echo $db->lastErrorMsg(); } else { echo "Opened database successfully\n"; } $sql =<<exec($sql); if(!$ret){ echo $db->lastErrorMsg(); } else { echo "Records created successfully\n"; } $db->close(); ?>
I have no idea what I'm doing wrong. Could anyone please help me?
<section id="content">
<div class="wrapper">
<h2>General Enquiry Form</h2>
<form id="FeedbackForm" action="post.php" method="post">
<div>
<div class="wrapper"> <span>Name:</span>
<input type="text" class="input" name="NAME">
</div>
<div class="wrapper"> <span>Contact:</span>
<input type="text" class="input" name="CONTACT">
</div>
<div class="wrapper"> <span>E-mail:</span>
<input type="text" class="input" name="EMAIL">
</div>
<div class="textarea_box"> <span>Message: (50char)</span>
<textarea name="COMMENT" cols="1" rows="1"></textarea>
</div>
<input type="submit" name="update" value="update">
<!--<span> </span> Clear Send </div>-->
</form>
</div>
</section>
Is the main section of the "form" html code from the whole code (content.html) that i showed above.
Change remove EOF thing and use double quotes for your sql, I think that's the problem.
$sql ="INSERT INTO Enquiry (Name,Contact,Email,Comment)
VALUES ( '$NAME', '$CONTACT', '$EMAIL', '$COMMENT' )";
most likely you redefined constructor to SQLite3 class itself.
http://www.php.net/manual/en/language.oop5.decon.php
try changing
function __construct() {
$this->open('final_mall_management_system.db');
}
to
function __construct() {
parent::__construct();
$this->open('final_mall_management_system.db');
}

Few problems at the same time, PHP

I'm working on one website but i'm confused.
<?php
ob_start("ob_gzhandler");
session_start();
define('FORUM_ROOT', 'forum/');
require FORUM_ROOT.'include/common.php';
// Where will we go after login?
$forum_page['redirect_url'] = 'http://l2topsites.net/';
$forum_page['form_action'] = forum_link($forum_url['login']);
$forum_page['hidden_fields'] = array(
'form_sent' => '<input type="hidden" name="form_sent" value="1" />',
'redirect_url' => '<input type="hidden" name="redirect_url" value="'.forum_htmlencode($forum_page['redirect_url']).'" />',
'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
);
include "conf.php";
$opala = $_GET['p'];
if (isset($opala)) {
$page = '_data/'.$opala.'.php';
} else {
$page = "_data/indexa.php";
}
if (!is_file($page)) {
echo 'This page not found!';
} else {
include "_data/".basename($page) ;
}
$sredata = ob_get_clean();
if(!isset($title)) $title = "[L2TopSites] - Top Lineage 2 Ranking Sites";
$online = mysql_fetch_assoc(mysql_query("SELECT SQL_CACHE COUNT(user_id) FROM `foo_online`"));
$online = $online['COUNT(user_id)'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title><? echo $title; ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="bg" />
<base href="http://l2topsites.net" />
<meta name="robots" content="all,follow" />
<meta name="google-site-verification" content="0G89ZsSF30caf4PJk17uLLtejlwnl8oO2mUN4ywZCw8" />
<meta name="description" content="Top Lineage2 Server only on TopZone.eu" />
<meta name="keywords" content="topzone, lineage2, servers, rank, votes, top10, top25, top100, lineage2 servers" />
<meta http-equiv="Cache-Control" content="max-age=3600" />
<link type="text/css" rel="stylesheet" href="/min/f=style.css" />
</head>
<body>
<div id="content">
<div id="maintop"></div>
<div id="main">
<div id="header">
<div id="lpanel">
<?
if (!$forum_user['is_guest'])
{
echo "<div class=\"usermenu\">";
echo "<img src=\"images/button1.png\" width=\"90\" height=\"23\" alt=\"\" /><br />";
echo "<img src=\"images/button2.png\" width=\"90\" height=\"23\" alt=\"\" /><br />";
echo "<img src=\"images/button3.png\" width=\"90\" height=\"23\" alt=\"\" />";
echo "</div><div id=\"ltext\" style=\"padding-top: 5px;\">";
echo "Logged in as: ".$forum_user['username']."";
if($forum_user['is_admmod']==1){
echo " | Admin Panel";
}
echo "</div>";
}
else
{
?>
<form action="<?php echo $forum_page['form_action'] ?>" method="post">
<?php echo implode("\n\t\t", $forum_page['hidden_fields'])."\n" ?>
<table border="0">
<tr><td width="10"><img class="img" src="images/user.png" width="17" height="19" alt="" /></td><td><input type="text" name="req_username" id="userinput" /></td></tr>
<tr><td width="10"><img class="img" src="images/pass.png" width="17" height="19" alt="" /></td><td><input type="password" name="req_password" id="passinput" /></td></tr>
</table>
<input type="submit" name="submit" value="" id="login" />
<img src="images/register.png" alt="" border="0" />
<div id="ltext">
Forget Password?
<input type="checkbox" id="input" name="save_pass" value="1" /><span>Remember me</span></div>
</form>
<? } ?>
</div>
</div>
<div id="mbaner1">
<div id="mb1l"></div>
<div id="mb1b">
<div id="mb1">
<img src="images/baner1.png" width="728" height="90" alt="" border="0" />
</div>
</div>
<div id="mb2r"></div>
</div>
<div id="left">
<div class="btop"></div>
<div class="mback">
<div id="box1t"></div>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
<div class="bbottom"></div>
<div class="btop"></div>
<div class="mback">
<div id="box2t"></div>
<ul>
<li>All Servers (by Vote)</li>
<li>All Servers (by Date)</li>
<li>Premium Servers</li>
<li>Search Server</li>
<li>Add Server</li>
</ul>
</div>
<div class="bbottom"></div>
<div class="btop"></div>
<div class="mback">
<div id="box3t"></div>
<ul>
<li>Crests</li>
<li>L2 Guides</li>
<li>Forum</li>
</ul>
</div>
<div class="bbottom"></div>
<div class="btop"></div>
<div id="aback">
<div id="box4t"></div>
<div id="adsense"><script type="text/javascript">
<!--
google_ad_client="pub-4584526598914996";google_ad_slot="3047263056";google_ad_width=121;google_ad_height=240;//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
</div>
<div class="bbottom"></div>
</div>
<div id="mcontent">
<div id="glineage"></div>
<div id="mcontenttop"></div>
<div id="mcontentt">
<?php
echo $sredata;
$btemi = mysql_fetch_assoc(mysql_query("SELECT SQL_CACHE COUNT(id) FROM foo_topics"));
$broitemi = $btemi['COUNT(id)'];
$bposts = mysql_fetch_assoc(mysql_query("SELECT SQL_CACHE COUNT(id) FROM foo_posts"));
$broipostove = $bposts['COUNT(id)'];
$bservers = mysql_fetch_assoc(mysql_query("SELECT SQL_CACHE COUNT(id) FROM s_servers WHERE `odobren` = '1'"));
$broiserveri = $bservers['COUNT(id)'];
?>
<div style="clear: both;"></div>
</div>
<div id="mcontentbottom"></div>
</div>
<div id="right">
<div id="fserver">
<?php
$q = mysql_fetch_assoc(mysql_query("SELECT SQL_CACHE `fname`, `fid` FROM `s_set`"));
echo "<b>".$q['fname']."</b>";
?>
</div>
<div class="btop"></div>
<div id="rback">
<div id="box5t"></div>
<ul>
<li>Gaming Forums</li>
<li>Counter-Strike</li>
<li>MuOnline</li>
<li>Ragnarok Online</li>
<li>World Of Warcraft</li>
<li>OnlineGames</li>
<li>OnlineTop100</li>
</ul>
</div>
<div class="bbottom"></div>
<div class="btop"></div>
<div class="mback">
<div id="box6t"></div>
<ul>
<li>Your ip is: <?=$_SERVER['REMOTE_ADDR']?></li>
<li>Servers indexed: <?=$broiserveri?></li>
<li>Threads on forum: <?=$broitemi?></li>
<li>Posts on forum: <?=$broipostove?></li>
<li>Online users: <?=$online?></li>
</ul>
</div>
<div class="bbottom"></div>
<div class="btop"></div>
<div class="mback">
<div id="box7t"></div>
<ul>
<li>Tutorials</li>
<li>Links Direcotory</li>
<li>You link here?</li>
</ul>
</div>
<div class="bbottom"></div>
</div>
<div id="footer">
<div id="fooleft"></div>
<div id="foo">
<ul>
<li>Home | </li>
<li>ViewServers | </li>
<li>Register | </li>
<li>Crests | </li>
<li>Forum | </li>
<li>AddServer | </li>
<li>Contact | </li>
<li>Privacy Policy | </li>
<li>Terms and Conditions</li>
</ul>
<span id="tend">All right reserved L2Topsites © 2010-2011
L2Topsites.net is not responsable for any external content.
</div>
<div id="fooright"></div>
</div>
<div id="mainbottom"></div>
</div>
</div>
<script type="text/javascript" src="/min/f=javascript.js"></script>
<!-- NACHALO NA TYXO.BG BROYACH -->
<script type="text/javascript">
<!--
d=document;d.write('<a href="http://www.tyxo.bg/?87885" title="Tyxo.bg counter" target=" blank"><img width="1" height="1" border="0" alt="Tyxo.bg counter"');d.write(' src="http://cnt.tyxo.bg/87885?rnd='+Math.round(Math.random()*2147483647));d.write('&sp='+screen.width+'x'+screen.height+'&r='+escape(d.referrer)+'" /><\/a>');//-->
</script>
<noscript><img src="http://cnt.tyxo.bg/87885" width="1" height="1" border="0" alt="Tyxo.bg counter" /></noscript>
</body>
</html>
Error is
`Warning: ob_start(): output handler 'ob_gzhandler' conflicts with 'zlib output compression' in D:\xampp\htdocs\index.php on line 2
Notice: ob_start(): failed to create buffer in D:\xampp\htdocs\index.php on line 2`
I don't know if it is because of that but links are broken too.
Its like when I click somewhere it goes to
index.php/page
but its should go on
index.php?p=page

Categories