Delete and update row using edit and delete image in php - php

This is my branch.php page and I want to delete and update row when the user click on the edit and delete image in php and directly the row should be deleted or updated in the table.But It is not working neither row is getting updated or deleted.
<?php
$a1=mysql_connect('localhost','root1','oec#123');
$b1=mysql_select_db('rms',$a1);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>branch</title>
<link href="styles/branch.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>Reporter Management System</h1>
<nav id="mainnav">
<ul>
<li>Home</li>
<li>Branch</li>
<li>Branch Admin</li>
<li>Reporters</li>
<li>Accountant</li>
<li>Settings</li>
<li>Log out</li>
</ul>
</nav>
</header>
<div id="hero">
<img src="News2.jpg" width="1000" height="320" alt=""/> </div>
<form role="form" action ="searchbranch.php" method="post">
<p><label for="Search">Search Branch :</label>
<input class="textbox" type="Search" placeholder="Name" name="Search">
<input type="submit" class="classname" value="Search" >
</form>
<form role= "form" action="createbranch.php" method="post">
<input type="submit" class="classname" value="Add Branch" onClick="href 'createbranch.php' " ></p>
</form>
<section class="page container">
<div>
<div class="span12">
<div class="box pattern ">
<div class="box-header">
<i class="icon-list"></i>
</div>
<table id="sample-table" class="table table-hover table-bordered tablesorter">
<thead>
<tr>
<th>Sl no</th>
<th>Branch</th>
<th>Description</th>
<th>Action</th>
</tr>
<?php
$w='SELECT Sl_no, branch, description from create_branch;';
$recordset=mysql_query($w,$a1) or die(mysql_error());
$totalrows=mysql_num_rows($recordset);
$row_recordset=mysql_fetch_assoc($recordset);
if($totalrows>0)
{
do
{
$r=$row_recordset['Sl_no'];
$d=$row_recordset['branch'];
$d1=$row_recordset['description'];
?>
</thead>
<tbody id='tb-content'>
<tr>
<td><?php echo $r ;?></td>
<td><?php echo $d ;?></td>
<td><?php echo $d1 ;?></td>
<td> <?php echo '
<a href="edit_branch.php?no='.$row_recordset['Sl_no'].'">'?>
<img src="pencil.png" />
<?php '</a>';? > | <?php echo'
<a href="branch_delete.php?no1='.$row_recordset['branch'].'">'?>
<img src="cross.png" /> <?php '</a>';?>
</td>
</tr>
<?php
}while($row_recordset=mysql_fetch_assoc($recordset));
}
mysql_free_result($recordset);
mysql_close($a1);
?>
</tbody>
</table>
</div>
</div>
</div>
</section>
</body>
<footer>
<p> </p><hr>
<center>©Copyright 2015 RepoterManagnmentSystem
</center>
</footer>
</div>
</body>
</html>
This is branch_delete.php
<?php
$cn=mysql_connect('localhost','root1',"oec#123");
$db_selected=mysql_select_db('rms',$cn);
$bn=$_REQUEST['no1'];
$sql='DELETE au.Sl_no,au.name,au.company_name,au.email_id,au.password,au.confirm_password,au.group,au.branch,au.phone,au.wordcount,au.rating,cb.Sl_no,cb.branch,cb.description from admin_user au,create_branch cb where cb.branch="'.$bn.'" AND au.branch=cb.branch ;';
$s1=mysql_query($sql,$cn);
mysql_close($cn);
header('Location: branch.php');
?>
This is update_branch.php
<?php
$a1=mysql_connect('localhost','root1','oec#123');
$b1=mysql_select_db('rms',$a1);
$bn=$_REQUEST['bname'];
$sn=$_REQUEST['Sl_no'];
$d=$_REQUEST['descp'];
$w= 'SELECT branch,description FROM create_branch;';
$recordset=mysql_query($w,$a1) or die(mysql_error());
$totalrows=mysql_num_rows($recordset);
$row_recordset=mysql_fetch_assoc($recordset);
if($totalrows>0)
{
do
{
$r=$row_recordset['branch'];
$s=$row_recordset['description'];
if($bn==$r and $d==$s)
{
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="styles/createbranch.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>Reporter Management System</h1>
<nav id="mainnav">
<ul>
<li>Home</li>
<li>Branch</li>
<li>Branch Admin</li>
<li>Reporters</li>
<li>Accountant</li>
<li>Settings</li>
<li>Log out</li>
</ul>
</nav>
</header>
<div id="hero">
<img src="News2.jpg" width="1000" height="320" alt=""/>
</div>
<form method="post" action="edit_branch.php">
<article id="main">
<?php echo '<h2>branch already exists</h2>' ; ?>
<h2>Create Branch</h2><hr>
<p><label for="branch name">Branch Name:</label><br><br>
<input class="textbox" type="text" placeholder=" <?php echo $bn ;?>" name="bname"></p><br>
<p><label for="Description">Description:</label><br><br>
<input class="textbox" type="text" placeholder="<?php echo $d ;?>" name="descp"></p><br>
<input type="submit" class="classname" value="Update Branch" ></p> <br>
</article>
</form>
<footer>
<p> </p><hr>
<center> © Copyright 2015 ReporterManagementSystem</center> </footer>
</div>
</body>
</html>
<?php
exit(0);
}
}
while($row_recordset=mysql_fetch_assoc($recordset));
$w1='UPDATE create_branch set branch="'.$bn.'" and description="'.$d.'" where Sl_no="'.$sn.'";';
$x=mysql_query($w1,$a1) or die(mysql_error());
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>Reporter Management System</h1>
<nav id="mainnav">
<ul>
<li>Home</li>
<li>Reporters</li>
<li>News Content</li>
<li>Add user</li>
<li>Log Out</li>
</ul>
</nav>
</header>
<img src="News2.jpg" width="1000" height="320" alt=""/>
<?php
echo "<br>";
if($x=="true")
{
header('Location: branch.php');
}
else
{
echo "fail to update branch";
}
echo"<br>";
}
mysql_free_result($recordset);
mysql_close($a1);
?>

The sql query incorrectly built.
To update an SQL query should look like this
UPDATE table_name SET
column1=value1,column2=value2,...
WHERE some_column=some_value;
Your update:
UPDATE create_branch SET
branch="'.$bn.'" ,
description="'.$d.'"
WHERE Sl_no="'.$sn.'"
Sql query - delete:
DELETE FROM table_name
WHERE some_column=some_value;
Your delete:
DELETE FROM create_branch
WHERE cb.branch="'.$bn.'"
Read MySQL documentation about FOREIGN KEY Constraints.
In the case of two tables joined the foreign key, delete or modify a record in the first result will be an appropriate operation on record in the second table.
Example:
MySQL Foreign Key On Delete

Related

title is stuck with everything in the center of the screen

So I would like to move up the big title a little bit so i leave space in the main page and css isn't helping i tried many methods like position:absolute , position:relative , position:fixed etc.. still nothing happens
html code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>AGENCE DE VOYAGES</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center>
<body background="ny.jpg" size="100%" width="100%" height="100%" align="center">
<header>
<div class="main">
<div class="logo">
<img src="logo.png">
</div>
<ul>
<li class="active">Accueil</li>
<li>Services</li>
<li>Clients</li>
<li>A Propos</li>
<li>Contact</li>
</ul>
</div>
<div class="title">
<h1 color="white">AGENCE DE VOYAGES</h1>
</div>
<div class="login">
<center>
<form action="auth.php" method="post">
<fieldset style="width:500px;">
<legend align='center'><h1>Connexion</h1></legend>
<table>
<tr>
<td><b>Email: </b></td>
<td><input type="email" name="email"></td>
</tr>
<tr>
<td><b>Mot de passe: </b></td>
<td><input type="password" name="password"></td>
</tr>
</div>
</table>
</fieldset>
</form>
<div class="button">
S'AUTHENTIFIER
S'INSCRIRE
</div>
</center>
</body>
</html>
I have left you an example of what you can do to move your text with css or make it smaller, hope that will solve your problem. I only added to your <h1> tag the class title like so:
<h1 class="title" color="white">AGENCE DE VOYAGES</h1>
.title{
font-size: 20px; /*You can choose here the size of your text*/
float: left; /*Or use right instead of left its up to you*/
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>AGENCE DE VOYAGES</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center>
<body background="ny.jpg" size="100%" width="100%" height="100%" align="center">
<header>
<div class="main">
<div class="logo">
<img src="logo.png">
</div>
<ul>
<li class="active">Accueil</li>
<li>Services</li>
<li>Clients</li>
<li>A Propos</li>
<li>Contact</li>
</ul>
</div>
<div class="title">
<h1 class="title" color="white">AGENCE DE VOYAGES</h1>
</div>
<div class="login">
<center>
<form action="auth.php" method="post">
<fieldset style="width:500px;">
<legend align='center'><h1>Connexion</h1></legend>
<table>
<tr>
<td><b>Email: </b></td>
<td><input type="email" name="email"></td>
</tr>
<tr>
<td><b>Mot de passe: </b></td>
<td><input type="password" name="password"></td>
</tr>
</div>
</table>
</fieldset>
</form>
<div class="button">
S'AUTHENTIFIER
S'INSCRIRE
</div>
</center>
</body>
</html>

How to change pages without changing url?

I am currently working on a project, but I'm just stuck on something. I know there are a lot of questions related to this, but I couldn't find any useful information.
I'm new to PHP and I need to write php code which changes pages and doesn't change the URL (i.e if I am going to login.php, the URL should still be home.php) and I need to use the GET method.
I'm sorry if there are some mistakes in my code, but thanks for any help.
Here is my home.php file:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="Layout.css" />
<link rel="stylesheet" type="text/css" href="Menu.css" />
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8" />
<title> Title </title>
</head>
<body>
<div id="Holder"></div>
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li> Home </li>
<li>Login </li>
<li>Register </li>
</ul>
</nav>
</div>
<div id="Content">
<div id="PageHeading">
<h1> Welcome to HOME page </h1>
</div>
</div>
<div id="Footer"></div>
</body>
</html>
Here is my login.php file:
<?php
session_start();
$db = mysqli_connect ("localhost", "root", "","information1");
if (isset($_POST['Register'])){
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$sql = "SELECT username, password FROM user WHERE username='$username' AND
password='$password'";
$base =mysqli_query ($db, $sql);
if (mysqli_num_rows($base) == 1) {
header ("location: nav_menu.php");
}
else
{
echo "Passwords does not match";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Layout.css" />
<link rel="stylesheet" type="text/css" href="Menu.css" />
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8" />
<title> Title </title>
</head>
<body>
<div id="Holder"></div>
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li> Home </li>
<li>Login </li>
<li>Register </li>
</ul>
</nav>
</div>
<div id="Content">
<div id="PageHeading">
<h1> Welcome to HOME page </h1>
</div>
<div id="ContentRight">
<h2> Text2 </h2> </br>
<h6> Text3 </h6 </br>
</div>
<div id="ContentLeft">
<form name ="form2" method="POST" action="login.php">
<div class = "ContentTable">
<table width="400" border="0" align ="left">
<tbody>
<h4> Username: </h4>
<input type="text" name= "username" id="username" required></td>
</tr>
<tr>
<td> </td>
</tr>
<h4> Password: </h4>
<input type="text" name= "password" id="password" required></td>
</tr>
<td><input type="submit" name="Register" id="RegisterButton" value="Register"></td>
</div>
</div>
</form>
<div id="Footer"></div>
</body>
</html>

Search bar not working correctly [duplicate]

Hello when i am searching a product from its keywords that i inserted in MYSQL all the products are appearing please help me this is the code of the search
i corrected as in the comments but it is till not working
This is my whole results page
<!DOCTYPE html>
<?php
include ("functions/functions.php");
?>
<html>
<head>
<title>eRiviera</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 rel="stylesheet" href="styles/style.css" media="all"/>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="js/menubarscript.js"></script>
</head>
<body>
<div class="main_wrapper">
<ul class="btn-circles">
<li>Login<span class="round">That is, if you already have an account.</span></li>
<li>Sign Up<span class="round">But only if you really, really want to.</span></li>
</ul>
<!--Header starts here-->
<div class="header_wrapper">
<!--Logo-->
<img id="logo" src="http://localhost/ecommerce/images/logo.png" width="500px" height="300px" alt="Logo" />
<!--Logo-->
</div>
<!--Header ends here-->
<!--Menu bar starts here-->
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.php'>Home</a></li>
<li><a href='#'>Products</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Contact</a></li>
<p style="float:right; margin-right:140px; margin-top:21px; color:red;">Welcome Guest!</p>
<li><a id="shopping_cart" style="margin:14px 0 0 0;left:750px; color:blue; font-size:12px;" href="cart.php">Shopping Cart</a></li>
</ul>
</div>
<form class="form-wrapper cf">
<input type="text" name="user_query" placeholder="Search here..." required>
<form method="get" action="results.php" enctype="multipart/form-data">
<button type="submit" name="search" value="Search">Search</button>
</form>
<ul id="cats">
<?php getCats(); ?>
</ul>
<!--Menu bar ends here-->
<!--Content wrapper starts here-->
<div class="content_wrapper">
<div id="content_area">
<div id="products_box">
<?php
if(isset$_GET['search'])) {
$search_query = $_GET['user_query'];
$get_pro = "select * from products where product_keywords like '%$search_query%'";
$run_pro = mysqli_query($con, $get_pro);
while($row_pro = mysqli_fetch_array($run_pro)) {
$pro_id = $row_pro['product_id'];
$pro_cat = $row_pro['product_cat'];
$pro_brand = $row_pro['product_brand'];
$pro_title = $row_pro ['product_title'] ;
$pro_price = $row_pro['product_price'];
$pro_image = $row_pro['product_image'];
echo "
<div id='single_product'>
<h3 id='product_title'>$pro_title</h3>
<img src='admin_area/product_images/$pro_image' width='180' height='200' />
<p><b> $ $pro_price <b></p>
<a id='details-button' href='details.php?pro_id=$pro_id'>Details</a>
<a href='index.php?pro_id=$pro_id'><button class='button'>Add to Cart</button></a>
</div>
";
}
}
?>
?>
</div>
</div>
</div>
<!--Content wrapper ends here-->
<div id="footer">
<h5 style="text-align:center; padding-top:30px;">©2014 eRiviera All Rights Reserved</h5>
</div>
<!--Main wrapper ends here-->
</body>
</html>
Your form is not properly structured - the "user_query" field is outside of the form so $_GET['user_query'] would never be set. Try changing this:
<form class="form-wrapper cf">
<input type="text" name="user_query" placeholder="Search here..." required>
<form method="get" action="results.php" enctype="multipart/form-data">
<button type="submit" name="search" value="Search">Search</button>
</form>
To something like this:
<div class="form-wrapper cf">
<form method="get" action="results.php" enctype="multipart/form-data">
<input type="text" name="user_query" placeholder="Search here..." required>
<button type="submit" name="search" value="Search">Search</button>
</form>
</div>
Also, as several others have noted, this is susceptible to SQL injection. This post discusses a scenario very similar to yours: How can I prevent SQL injection in PHP?
I strongly suggest you run your generated code through a validation service in order to catch errors in your html. Be sure to use the generated html (copy from "view source" in browser), not just the code from your php file because the validator won't understand the PHP. The WWW Consortium has a good tool: http://validator.w3.org/#validate_by_input

Is it possible to get 'Session User" to display

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>

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