SQL failing in one page on some machines - php

Edit: Forgot to mention none of the SQL works at all when it fails.
I seriously need help figuring this out. It has been about a month since the issue has arrived. I have rewrote the page a couple times and have tried removing some unneeded items in case it was a speed issue (had sidebar that auto scrolled and loaded in two social media widgets which was kinda slow on bad internet) and so far nothing. I really do not know why this happens at all.
Here is the kicker. It only happens to random people. Never breaks for me but breaks nearly every time for a customer on certain pc's. Another issue that person is running into is the cart cookie won't clear for that person either(just them).
I am Using Auth.net's DPM method which takes them offsite momentarily then to my Order_receipt page(the one in question). When arriving at that page you are given 2 $_GET properties example (order_receipt.php?response_code=1&transaction_id=136434353) which is coming in properly even when it fails.
Customer that has issue is using win 10, and has tried it with both chrome and edge running kaspersky antivirus (no issues on my end from either browser)
I'm going to include all code loaded and included in that page below, starting with the order_receipt itself.
** = redacted info
Order_receipt.php:
<?php
require_once 'system/init.php';
include 'includes/head.php';
include 'includes/navigation.php';
include 'includes/headerpartial.php';
?>
<div id="maincontent" class="col-md-12">
<?php
ini_set('error_reporting', -1); ini_set('display_errors', 'on');
ini_set('log_errors', 1);
ini_set('error_log', 'system/error_logs.log');
$error_code = uniqid(mt_rand(), true);
if ($_GET['response_code'] == 1)
{
$trans_id = $_GET['transaction_id'];
if (isset($cart_id)){
$db->query("UPDATE transactions SET charge_id = '$trans_id' WHERE cart_id = '$cart_id'");
$tsql = $db->query("SELECT * FROM transactions WHERE cart_id = '$cart_id' ");
$tran = mysqli_fetch_assoc($tsql);
?>
<h1 id="reciept">Thank you for your support!</h1><hr>
<p id="reciept">
On behalf of ** <?=$tran['full_name']?> we thank you for your purchase and hope you enjoy it!
</p>
<p id="reciept">
You have selected <b>"<?=$tran['pickup-location']?>"</b> as your pickup point.
</p>
<table id="nav-button" class="table table-bordered table-auto">
<tbody>
<tr>
<td>Transaction ID : <?=$tran['charge_id']?></td>
</tr>
<?php
$a = 1;
$it = 1;
$string = $tran['items'];
$itemar = explode(',', $string);
$num = 1;
$istr = $tran['inventory'];
$stri = explode(',', $istr);
if ($tran['status'] != "Complete") {
foreach (array_slice($stri, $num) as $inve ){
$exploded = explode('.', $inve);
$itname = $exploded['0'];
$itquan = $exploded['1'];
$db->query("UPDATE products SET `quantity` = `quantity` - '$itquan' WHERE title = '$itname'");
$db->query("UPDATE products SET `Sold` = `Sold` + '$itquan' WHERE title = '$itname'");
$it++;
}
$compl = "Complete";
$db->query("UPDATE transactions SET `status` = '$compl' WHERE cart_id = '$cart_id'");
}
foreach (array_slice($itemar, $num) as $itemr ){
?>
<tr>
<td><?=$itemr?></td>
</tr>
<?php
$a++;
} ?>
<tr>
<td>
Total: <?=money($tran['grand_total']);?>
</td>
</tr>
</tbody>
</table>
<?php
$domain = '.'.$_SERVER['HTTP_HOST'];
setcookie(CART_COOKIE,'',1,"/",$domain,false);
}else{echo "Cart Id not Set";}
}else
{
echo "Sorry, an error occurred: ".htmlentities($_GET['response_reason_text']);
}?>
</div>
<?php
include 'includes/footer.php';
?>
Init.php:
<?php
$db = mysqli_connect("**","**","**","**");
if(mysqli_connect_errno()){
echo 'Database connection failed with following errors: '. mysqli_connect_error();
die();
}
session_start();
require_once $_SERVER['DOCUMENT_ROOT'].'/config.php';
require_once BASEURL.'helpers/helpers.php';
$cart_id = '';
if(isset($_COOKIE[CART_COOKIE])){
$cart_id = sanitize($_COOKIE[CART_COOKIE]);
}
if (isset($_SESSION['LHUser'])) {
$user_id = $_SESSION['LHUser'];
$query = $db->query("SELECT * FROM users WHERE id = '$user_id'");
$user_data = mysqli_fetch_assoc($query);
$fn = explode(' ', $user_data['full_name']);
$user_data['first'] = $fn[0];
$user_data['last'] = $fn[1];
}
if (isset($_SESSION['success_flash'])) {
echo '<div class="bg-success"><p class="text-success text-center">'.$_SESSION['success_flash'].'</p></div>';
unset($_SESSION['success_flash']);
}
if (isset($_SESSION['error_flash'])) {
echo '<div class="bg-danger"><p class="text-danger text-center">'.$_SESSION['error_flash'].'</p></div>';
unset($_SESSION['error_flash']);
}
?>
config.php:
<?php
define('BASEURL', $_SERVER['DOCUMENT_ROOT'].'/');
define('CART_COOKIE','Sd4CqdgRt6J3gd3F7');
define('CART_COOKIE_EXPIRE', time() + (86400 * 30));
?>
helpers.php:
<?php
ob_start();
function display_errors($errors){
$display = '<ul class="bg-danger">';
foreach ($errors as $error) {
$display .= '<li class="text-danger">'.$error.'</li>';
}
$display .= '</ul>';
return $display;
}
function sanitize($dirty){
return htmlentities($dirty,ENT_QUOTES,"UTF-8");
}
function money($number){
return '$'.number_format($number,2);
}
function login($user_id){
$_SESSION['LHUser'] = $user_id;
global $db;
$date = date("Y-m-d H:i:s");
$db->query("UPDATE users SET last_login = '$date' WHERE id = '$user_id'");
$_SESSION['success_flash'] = 'You are now logged in!';
header('Location: index.php');
}
function is_logged_in(){
if (isset($_SESSION['LHUser']) && $_SESSION['LHUser'] > 0) {
return true;
}
return false;
}
function login_error_redirect($url = 'login.php'){
$_SESSION['error_flash'] = 'You must be logged in to access that page';
header('Location:'.$url);
}
function permission_error_redirect($url = 'login.php'){
$_SESSION['error_flash'] = 'You don\'t have permission to access that page';
header('Location:'.$url);
}
function has_permission($permission = 'admin'){
global $user_data;
$permissions = explode(',', $user_data['permissions']);
if (in_array($permission,$permissions,true)) {
return true;
}
return false;
}
function get_category($child_id){
global $db;
$id = sanitize($child_id);
$sql = "SELECT p.id AS 'pid', p.category AS 'parent', c.id AS 'cid', c.category AS 'child'
FROM categories c
INNER JOIN categories p
ON c.parent = p.id
WHERE c.id = '$id'";
$query = $db->query($sql);
$category = mysqli_fetch_assoc($query);
return $category;
}
head.php:
<!DOCTYPE html>
<html>
<head>
<title>LettuceHeads</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
<link rel="icon" href="../images/header/logoicon.png">
<meta name="Viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script SRC="js/bootstrap.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
navigation.php:
<?php
$sql = "SELECT * FROM navigation ORDER BY `navigation`.`sort` ASC";
$pquery = $db->query($sql);
?>
<nav id="navbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
<div id="navtext" class="containter">
<a id="navborder" href="index.php" class="navbar-brand">**</a>
<ul class="nav navbar-nav">
<?php while($parent = mysqli_fetch_assoc($pquery)) : ?>
<li id="navborder"><?=$parent['name'];?></li>
<?php endwhile; ?>
</li>
</ul>
<ul id="navright" class="nav navbar-nav navbar-right" >
<li id="navborder2"><span class = "glyphicon glyphicon-shopping-cart"></span> My Cart</li>
<?php if(has_permission('admin')): ?>
<li id="navborder">Staff</li>
<?php endif; ?>
</ul>
</div>
</nav>
headerpartial.php:
<div id="partialHeaderWrapper">
<div id="partialbackitem"></div>
<div id="partiallogotext"></div>
<div id="partialfore-item"></div>
</div>
<div class="container-fluid">
footer.php:

Related

Rerun of a mysql query

im working on a existing website and the code is built with functions .
now , i have a function that fetches the ID of an article , and in this function theres a function that puts a value that says "username X has enter Article Y"
now problem is , that it should go in to the database only once , but it seems to go in once with the title and it keeps going in the DB without a title for a few times . no idea why . it isnt my code .
any chance you guys have a solution how i can resolve this issue ?
i should add that i checked for loops and it doesnt seem to be in one .
function article($id = null){
if(!$id) return 0;
countViewsByPost($id);
$qq = mysql_query("SELECT * FROM articles WHERE id = $id AND valid='1'");
$row = mysql_fetch_assoc($qq);
$markup = null;
history_actions( 'משתמש '.userID('username').' נכנס לכתבה '.$row['title'] );
$markup .= '<br /><br /><br /><br /><div class="container p0 mb10"><a class="goBackContent" href="'.base_url().'articles" >חזור</a></div>';
if(mysql_num_rows($qq) > 0){
$markup .='
<div class="container pb30 br8 content_page">
<div class="container container-main-h2">
<h5 style="color:#000000;">פורסם ב '.date('d.m.y',strtotime($row['created'])).' ע"י '.get_level_of_user($row['userID']).'</h5>
<span style="color:#000000;"><b>צפיות</b> : '.$row['views'].'</span>
<div><div class="fb-share-button" data-href="'.base_url().'articles/'.$row['id'].'" data-layout="button_count" data-mobile-iframe="true"></div></div><br>
</div>
<div class="col-lg-12 text-center mb20"><h1>'.$row['title'].'</h1></div>
<div class="col-lg-12">'.$row['text'].'</div>
</div>
';
$markup .='
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/he_IL/sdk.js#xfbml=1&version=v2.6";
fjs.parentNode.insertBefore(js, fjs);
}(document, \'script\', \'facebook-jssdk\'));</script>
';
}
else{
header('location:'.base_url());
}
return $markup;
}
the code of the history
function history_actions($action = FALSE){
if(!$action){
return false;
}
$action = mres($action);
$ip = $_SERVER['REMOTE_ADDR'];
$userID = mres( userID('id')) ;
$sql = "INSERT INTO history_actions_web(userID,ip,action) VALUES($userID,'$ip','$action')";
// var_dump($sql);die();
mysql_query($sql);
}
The history_actions function must be called only if an article exists.
...
if(mysql_num_rows($qq) > 0){
history_actions( 'משתמש '.userID('username').' נכנס לכתבה '.$row['title'] );
...

My web page is fine on my server, but my local copy gives a parser error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I have a PHP website and the index page displays fine online, but my local copy running on my wamp server gives me a parser error "Parse error: syntax error, unexpected end of file in..."
My local PHP is the same as my production. 5.6
I looked at previously asked question PHP parse/syntax errors; and how to solve them? and it mentions nothing about end of file.
Here is my code:
<?php
include "Calls.php";
my_session_start();
$sessionid = #$_SESSION["id"];
ini_set ("display_errors", "1");
error_reporting(E_ALL);
ini_set('short_open_tag',true);
include "production.class.php";
include "emailFunctions.php";
$selection="";
$mat = "";
include "currentSeason.php";
//current production
$currProd = new Production($arrSeason[0]['logo'],$arrSeason[0]['odate'],$arrSeason[0]['cldate'],$arrSeason[0]['credits'],$arrSeason[0]['director'],$arrSeason[0]['synopsis'],$arrSeason[0]['characters'],$arrSeason[0]['cast'],$arrSeason[0]['actors'],$arrSeason[0]['photos'],$arrSeason[0]['crewPositions'],$arrSeason[0]['crewNames'],$arrSeason[0]['season'],$arrSeason[0]['shownum'],$arrSeason[0]['showname'],$arrEntireSeason[0]['auddate'],$arrEntireSeason[0]['Special'],$arrEntireSeason[0]['Rights'],$arrSeason[0]['rightsText'],$arrEntireSeason[0]['matinee'],$arrEntireSeason[0]['ticketform'],$arrEntireSeason[0]['Promotion'],$arrEntireSeason[0]['misc'],$arrEntireSeason[0]['Type']);
$curshow=$currProd->getshownumber();
$arrSize = $aS+$aaud+$aevents+$aalerts;
$Events = array();
for($x=0;$x<sizeof($arrSeason);$x++){
$Events[$x][0] = "show";
$Events[$x][1] = $arrSeason[$x]["showname"];
$Events[$x][2] = $arrSeason[$x]["odate"];
$Events[$x][3] = $arrSeason[$x]["cldate"];
$Events[$x][4] = $arrSeason[$x]["director"];
$Events[$x][5] = $arrSeason[$x]["credits"];
$Events[$x][6] = $arrSeason[$x]["season"];
$Events[$x][7] = "";
$Events[$x][8] = "";
$Events[$x][9] = "";
$Events[$x][10] = $arrSeason[$x]["shownum"];
$Events[$x][11] = $arrSeason[$x]["cast"];
$Events[$x][12] = $arrSeason[$x]["Promotion"];
}
if($aaud>1){
for($a1=0;$a1<sizeof($arrAudInfo);$a1++){
$Events[$x][0] = "audition";
$Events[$x][1] = $arrAudInfo[$a1]["showname"];
$Events[$x][2] = $arrAudInfo[$a1]["auddate"];
$Events[$x][3] = "";
$Events[$x][4] = "";
$Events[$x][5] = "";
$Events[$x][6] = $arrAudInfo[$a1]["season"];
$Events[$x][7] = $arrAudInfo[$a1]["when"];
$Events[$x][8] = $arrAudInfo[$a1]["where"];
$Events[$x][9] = $arrAudInfo[$a1]["matOnline"];
$Events[$x][10] = $arrAudInfo[$a1]["shownum"];
$Events[$x][11] = "";
$Events[$x][12] = $arrAudInfo[$a1]["audID"];
$x+=1;
}
}
if($aaud==1){
$Events[$x][0] = "audition";
$Events[$x][1] = $arrAudInfo[0]["showname"];
$Events[$x][2] = $arrAudInfo[0]["auddate"];
$Events[$x][3] = "";
$Events[$x][4] = "";
$Events[$x][5] = "";
$Events[$x][6] = $arrAudInfo[0]["season"];
$Events[$x][7] = $arrAudInfo[0]["when"];
$Events[$x][8] = $arrAudInfo[0]["where"];
$Events[$x][9] = "";
$Events[$x][10] = $arrAudInfo[0]["shownum"];
$Events[$x][11] = "";
$Events[$x][12] = $arrAudInfo[0]["audID"];
$x+=1;
}
if($aevents>1){
for($a2=0;$a2<sizeof($arrEvents);$a2++){
$Events[$x][0] = "event";
$Events[$x][1] = $arrEvents[$a2]["Event"];
$Events[$x][2] = $arrEvents[$a2]["eventDate"];
$Events[$x][3] = "";
$Events[$x][4] = "";
$Events[$x][5] = "";
$Events[$x][6] = "";
$Events[$x][7] = "";
$Events[$x][8] = $arrEvents[$a2]["where"];
$Events[$x][9] = "";
$Events[$x][10] = $arrEvents[$a2]["ID"];
$Events[$x][11] = $arrEvents[$a2]["EventDetails"];
$x+=1;
}
}
if($aevents == 1){
$Events[$x][0] = "event";
$Events[$x][1] = $arrEvents[0]["Event"];
$Events[$x][2] = $arrEvents[0]["eventDate"];
$Events[$x][3] = "";
$Events[$x][4] = "";
$Events[$x][5] = "";
$Events[$x][6] = "";
$Events[$x][7] = "";
$Events[$x][8] = $arrEvents[0]["where"];
$Events[$x][9] = "";
$Events[$x][10] = $arrEvents[0]["ID"];
$Events[$x][11] = $arrEvents[0]["EventDetails"];
}
if($aalerts == 1){
$Events[$x][0] = "alert";
$Events[$x][1] = $arrAlerts[0]["Alert"];
$Events[$x][2] = $arrAlerts[0]["alertDate"];
$Events[$x][3] = "";
$Events[$x][4] = "";
$Events[$x][5] = "";
$Events[$x][6] = "";
$Events[$x][7] = "";
$Events[$x][8] = $arrAlerts[0]["where"];
$Events[$x][9] = "";
$Events[$x][10] = $arrAlerts[0]["ID"];
$Events[$x][11] = $arrAlerts[0]["AlertDetails"];
}
//Sort events by date
array_sort_by_column($Events,2);
//register email
if(isset($_POST['emailSub'])){
joinEmail($_POST['email']);
}
function array_sort_by_column(&$array, $column, $direction = SORT_ASC){
$reference_array = array();
foreach($array as $key => $row){
$reference_array[$key] = $row[$column];
}
array_multisort($reference_array, $direction, $array);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>The Little Theatre of Jefferson City</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="images/favicon.ico" />
<script src="scripts/plugins.js"></script>
<script>
function getCast(num,season){
document.getElementById("showDetails").src = "cast.php?season=" + season + "&shownum=" + num;
}
function getAudInfo(num,season,aid){
//alert(aid);
document.getElementById("showDetails").src = "viewAudInfo.php?aid=" + aid + "&season=" + season + "&shownum=" + num;
}
function getEvent(num){
//alert(num)
document.getElementById("showDetails").src = "eventdetail.php?event=" + num;
}
function getAlert(num){
//alert(num)
document.getElementById("showDetails").src = "alertdetail.php?alert=" + num;
}
function getVideo(file,auto){
document.getElementById('player2').src="video.php?video="+file+"&auto="+auto;
}
</script>
<style type="text/css">
#dhtmltooltip{
font-size: 12px;
position: absolute;
width: 200px;
border: 3px inset black;
padding: 2px;
background-color: lightyellow;
visibility: hidden;
z-index: 100;
/*Remove below line to remove shadow. Below line should always appear last within this CSS*/
filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
}
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-39749769-1', 'tltjc.org');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="dhtmltooltip"></div>
<script type="text/javascript">
/***********************************************
* Cool DHTML tooltip script- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
selectArray=new Array("Click on the Prison Brews logo to download a special promotion for Whorehouse ticket holders!")
var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=selectArray[thetext]
enabletip=true
return false
}
}
function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"
//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}
function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}
document.onmousemove=positiontip
</script>
<div id="main">
<div class="container">
<div id="header">
<div id="logo">
</div>
</div>
<?php include "menu.php" ?>
<div id="block_collage" class="block_flash">
<script type="text/javascript">
if (pluginlist.indexOf("Flash")!=-1){
document.write ("<embed src='images\/collage.swf' wmode='transparent' quality='high' pluginspage='http:\/\/www.macromedia.com\/go\/getflashplayer' type='application\/x-shockwave-flash' width='938' height='264'><\/embed>");
}
</script>
</div>
<div id='SpecialAnnouncement' class="block">
<h2>Now Available</h2>
<h3>Purchase your memberships online</h3><br />
You can now purchase 2016-2017 Season Memberships at all levels right here on our website! Follow this link to purchase your membership using your Visa, Mastercard or Discover.
</div>
<div id="leftpane">
<div id="block_featured" class="block">
<h2>Upcoming TLT Events</h2>
<?
for($zzz=0;$zzz<sizeof($Events);$zzz++){
?>
<div class="event">
<? if($Events[$zzz][0]=="show"){?>
<h4>
<a href="seasons.php?shownum=<?=$Events[$zzz][10]?>&curs=<?= $Events[$zzz][6]?>">
<?=switchThe($Events[$zzz][1])?>
</a>
</h4>
<div class="showinfo">
<? if(strpos($Events[$zzz][5],"by")==0){ echo "by"; }?> <?=switchThe($Events[$zzz][5])?><br/>
directed by <?=$Events[$zzz][4]?><? if(strpos($Events[$zzz][1],"Whorehouse")>0){?> <img src="images/prisonbrews_logo.jpg" style="float:right" /><? } ?><br/>
<? if(date("d",strtotime($Events[$zzz][2]))==01){?>
Show dates: <?=date("M",strtotime($Events[$zzz][2])).", ".date("Y",strtotime($Events[$zzz][3]))?><br/>
<? } else{?>
Show dates: <?=date("M",strtotime($Events[$zzz][2]))." ".date("d",strtotime($Events[$zzz][2]))."-".date("d",strtotime($Events[$zzz][3])).", ".date("Y",strtotime($Events[$zzz][3]))?><br/>
<? } ?>
</div>
<? } ?>
<? if($Events[$zzz][0]=="audition"){?>
<h4><? echo "Auditions-".switchThe($Events[$zzz][1])?></h4>
<div class="showinfo">
When: <?=date("M",strtotime($Events[$zzz][2]))." ".date("d",strtotime($Events[$zzz][2])).", ".date("Y",strtotime($Events[$zzz][2]))." at ".$Events[$zzz][7]?><br/>
Where: <?=$Events[$zzz][8]?>
</div>
<? } ?>
<? if($Events[$zzz][0]=="event"){?>
<h4><?=switchThe($Events[$zzz][1])?></h4>
<div class="showinfo">
When: <?=date("M",strtotime($Events[$zzz][2]))." ".date("d",strtotime($Events[$zzz][2])).", ".date("Y",strtotime($Events[$zzz][2]))?><br/>
Where: <?=$Events[$zzz][8]?>
</div>
<? } ?>
<? if($Events[$zzz][0]=="alert"){?>
<h4 class="alertLink"><?=switchThe($Events[$zzz][1])?></h4>
<div class="showinfo">
Where: <?=$Events[$zzz][8]?>
</div>
<? } ?>
</div><br/><br/>
<? } ?>
</div>
<div id="block_multimedia" class="block">
<div id="videoheader" class="sectionheader">
Multimedia
</div><br/><br/>
<!--<video controls style="margin-left:50px;">
<source src="images/Video/Jamie_Waier_WUD.webm" type="video/webm" />
</video>
<h2><em>Cast Interviews</em>('Wait Until Dark')</h2>-->
See video clips here!
</div>
</div>
<div id="rightpane">
<div id="block_currentInfo" class="block"><a name="ci"></a>
<? if(($Events[0][0]=="audition")&&($Events[0][2]!="0000-00-00")){?>
<iframe src="viewAudInfo.php?aid=<?=$Events[0][12]?>&season=<?=$Events[0][6]?>&shownum=<?=$Events[0][10]?>"
scrolling="yes" frameborder="0" id="showDetails" name="showDetails" height="665" width="99%" />
<? } else if($Events[0][0]=="event"){?>
<iframe src="eventdetail.php?event=<?=$Events[0][10]?>"
scrolling="yes" frameborder="0" id="showDetails" name="showDetails" height="665" width="99%" />
<? } else if($Events[0][0]=="show"){?>
<iframe src="cast.php?season=<?=$Events[0][6]?>&shownum=<?=$Events[0][10]?>"
scrolling="yes" frameborder="0" id="showDetails" name="showDetails" height="665" width="98%">
<? } ?>
</iframe>
</div>
<div id="block_signup" class="block">
<div id="signupheader" class="sectionheader">
Stay Informed
</div>
How can you keep yourself informed of everything that TLT does, including audition announcements,
ticket sales, performance reviews and more? There is more than one way! Read more below:
<hr />
Join our email list. When TLT makes a major announcement, we always send out an email about it.
<?php if(isset($_COOKIE['emailadd'])){ ?>
<br /><strong>You are registered on our email list as: <br /><?=$_COOKIE['emailadd']?></strong>
<? } else{?>
Enter your email address to sign up for our email list:<span style="color:red;"><?=$errormsg?></span>
<form action="http://cwebsolutions.net/dada/mail.cgi" method="post" accept-charset="UTF-8" id="subscription_form">
Email: <input type="text" name="email" size="40"/>
<input type="submit" name="emailSub" value="Sign Up" />
</form>
<? }?>
<hr />
Social networking is hot! Join our <a href='http://www.facebook.com/#/group.php?gid=55791655556&ref=ts' target='_blank'><img src='images/fb_icon.jpg' style='border:none;' />Facebook goup</a> and follow us on <a href='http://twitter.com/tltjc' target='_blank'><img src='images/Twitter-icon.png' style='border:none;' />Twitter</a>. We update them often.
<hr />
Subscribe to our <a href='newsfeed.php'>RSS newsfeed</a>. You'll be able to see all of our recent news as soon as it's posted.
</div>
</div>
<? include "footer.php" ?>
</div></div></body>
</html>
Most probably the combined use of normal and short open tag at the end of your document. Specifically this line:
<?php if(isset($_COOKIE['emailadd'])){ ?>
This line is opened with a normal tag. But the end of the if statement is not:
<? }?>
This causes PHP to conclude the document is not complete at the last line because it is still expecting a close tag from that if.
Short open tags are disabled by default on new installations. Presumably one installation has it enabled, and the other has not. Either enable short open tags in php.ini or replace them with normal open tags. At least using the same tag consistently will cause a more regular behavior.
Php codes will show errors because of too many things. Some of them may consider the version of PHP. If your PHP Program is latest PHP 5 or above, You must need to install that latest version of Wamp in your PC. Otherwise, it will show errors like this.

PHP and HTML commenting system

I'm trying to build a comment system
this is my code
<html>
<head>
<link rel="stylesheet" type="text/css" href="css.css">
<style>
.back_glob{width: 350px}
</style>
<script type="text/javascript" src="jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(function(){
$( ".tombol_login" ).click(function() {
var txt = $("[name=comment]").val();
$("#comment").submit();
})});
</script>
<style>
.back_glob{width: 450px}
</style>
</head>
<body>
<div class = "back_glob">
<div class="tableC">
<img src="img\back.png" alt="back" height="42" width="42">
<div class ="back_header">
<h4>comment</h4>
</div>
<div class= "table">
<form id="comment" name="comment" action="contet2.php" method="post">
<div class="row">
<div class="col">comment</div>
<div class="col">:</div>
<div class="col"><textarea name="comment" rows ="10" cols="40"></textarea></div>
</div>
<div class="tom">
<button type="button" class="tombol_login">Submit</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<?php
$servername = "localhost";
$dbname = "databaseform";
$username = "root";
$password = "";
session_start();
$page = 2;
$conn = new PDO("mysql:host =$servername ; dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "SELECT form.Username, comment.Comment, comment.time FROM
form, comment WHERE
form.pkey=comment.pkey AND
comment.page=$page
ORDER BY comment.time DESC";
$result = $conn->query($query);
$hasil = $result->fetchAll();
$Comment = $_POST['comment'];
try
{
// injec
$query = "INSERT INTO comment (pkey,Comment,time,page)
VALUES (:Username,:Comment,NOW(),:page)";
$sql = $conn->prepare($query) ;
$sql->BindValue(':Username',reset($_SESSION['txt_login']));
$sql->BindValue(':Comment',$Comment);
$sql->BindValue(':page',$page);
$sql->execute();
$query = "SELECT form.Username, comment.Comment, comment.time FROM
form, comment WHERE
form.pkey=comment.pkey AND
comment.page=$page
ORDER BY comment.time DESC";
$result = $conn->query($query);
$hasil = $result->fetchAll();
echo '<div class="back_glob">';
echo '<div class = "table">';
echo '<div class = "tableC">';
echo '</div>';
}
catch(PDOException $e)
{
echo $query . "<br>" . $e->getMessage();
}
for($i = 0 ; $i < count($hasil);$i++)
{
echo'<div class="row">';
echo '<div class="col2">'.$result[$i]['Username'].'</div>';
echo '<div class="col2">'.$result[$i]['Comment'].'</div>';
echo '<div class="col2">'.$result[$i]['time'].'</div>';
echo'</div>';
}
?>
but the php part won't recognize the $_POST['comment'] before the submit button , i can't show the previous comment unless I click the submit button.
Is there any solution to correct this ??
I am really confused about your way of asking a question. I think you should have to read this tutorial of Smashing Magazine. So you can better understand of code and comment system.
I hope it will help you.

PHP + mysqli trying to set up settings site for logged in user

I'm learning php and I'm using a tutorial to build a small community site.
I already have sign up, login and lost password set up as well as a profile page where the user can see his data which is saved in the database.
Now I'm trying to create a settings page where the user can edit his information and I scaled it down to just change the password for now for testing purposes.
So, to see if the user is logged in, I have this function, which I included on my settings page:
<?php
include_once("db_conx.php");
// Files that inculde this file at the very top would NOT require
// connection to database or session_start(), be careful.
// Initialize some vars
$user_ok = false;
$log_id = "";
$log_username = "";
$log_password = "";
// User Verify function
function evalLoggedUser($conx,$id,$u,$p){
$sql = "SELECT ip FROM users WHERE id='$id' AND username='$u' AND password='$p' AND activated='1' LIMIT 1";
$query = mysqli_query($conx, $sql);
$numrows = mysqli_num_rows($query);
if($numrows > 0){
return true;
}
}
if(isset($_SESSION["userid"]) && isset($_SESSION["username"]) && isset($_SESSION["password"])) {
$log_id = preg_replace('#[^0-9]#', '', $_SESSION['userid']);
$log_username = preg_replace('#[^a-z0-9]#i', '', $_SESSION['username']);
$log_password = preg_replace('#[^a-z0-9]#i', '', $_SESSION['password']);
// Verify the user
$user_ok = evalLoggedUser($db_conx,$log_id,$log_username,$log_password);
} else if(isset($_COOKIE["id"]) && isset($_COOKIE["user"]) && isset($_COOKIE["pass"])){
$_SESSION['userid'] = preg_replace('#[^0-9]#', '', $_COOKIE['id']);
$_SESSION['username'] = preg_replace('#[^a-z0-9]#i', '', $_COOKIE['user']);
$_SESSION['password'] = preg_replace('#[^a-z0-9]#i', '', $_COOKIE['pass']);
$log_id = $_SESSION['userid'];
$log_username = $_SESSION['username'];
$log_password = $_SESSION['password'];
// Verify the user
$user_ok = evalLoggedUser($db_conx,$log_id,$log_username,$log_password);
if($user_ok == true){
// Update their lastlogin datetime field
$sql = "UPDATE users SET lastlogin=now() WHERE id='$log_id' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
}
}
?>
And this is the settings page:
<?php
include 'php_includes/db_conx.php';
include 'php_includes/login_ex.php';
include_once("php_includes/check_login_status.php");
// Initialize any variables that the page might echo
$u = "";
$sex = "Male";
$userlevel = "";
$country = "";
$joindate = "";
$lastsession = "";
$password = "";
// Make sure the _GET username is set, and sanitize it
if(isset($_GET["u"])){
$u = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
} else {
header("location: index.php");
exit();
}
// Select the member from the users table
$sql = "SELECT * FROM users WHERE username='$u' AND activated='1' LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
// Now make sure that user exists in the table
$numrows = mysqli_num_rows($user_query);
if($numrows < 1){
echo "That user does not exist or is not yet activated, press back";
exit();
}
// Check to see if the viewer is the account owner
$isOwner = "no";
if($u == $log_username && $user_ok == true){
$isOwner = "yes";
}
// Fetch the user row from the query above
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$profile_id = $row["id"];
$gender = $row["gender"];
$country = $row["country"];
$userlevel = $row["userlevel"];
$signup = $row["signup"];
$lastlogin = $row["lastlogin"];
$joindate = strftime("%b %d, %Y", strtotime($signup));
$lastsession = strftime("%b %d, %Y", strtotime($lastlogin));
if($gender == "f"){
$sex = "Female";
}
}
?>
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="robots" content="index, follow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.css" rel="stylesheet" media="screen" type="text/css">
<link href="css/custom.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap-min.css" rel="stylesheet" media="screen" type="text/css">
<script src="js/main.js"></script>
<title>KZ|Language exchange</title>
</head>
<body>
<div id="custom-bootstrap-menu" class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">Brand</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-menubuilder"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navbar-menubuilder">
<ul class="nav navbar-nav navbar-left">
<li>Home
</li>
<li>Profile
</li>
<li>About Us
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><?php
if ($isOwner == "yes") {?>
<a class="navbar-brand" href="logout.php" style="border-left: 1px solid; padding-left: 10px;">Logout</a>
<?php
}
?>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="row-fluid">
<div class="col-md-9">
<h3><?php echo $u; ?></h3>
<p>Is the viewer the page owner, logged in and verified? <b><?php echo $isOwner; ?></b></p>
<p>Gender: <?php echo $sex; ?></p>
<p>Country: <?php echo $country; ?></p>
<p>User Level: <?php echo $userlevel; ?></p>
<p>Join Date: <?php echo $joindate; ?></p>
<p>Last Session: <?php echo $lastsession; ?></p>
<p>Password: <?php echo $password; ?></p>
<?php var_dump($_SESSION);
var_dump($_SESSION['username']);
?>
<?php
// i need to make sure that $isOwner = "yes"; so only logged in users see the form and can change the password
if (isset($_POST['submit'])) {
$password = $_POST["password"];
var_dump($password);
$sql = "UPDATE users SET password='$password' WHERE username='$u'";
}
?>
<h3>Create new password</h3>
<form action="user.php" method="post">
<div>Password</div>
<input type="text" class="form-control" id="password" name="password">
<br /><br />
<input type="submit" name="submit" value="Submit">
<p id="status" ></p>
</form>
</div>
<div class="col-md-3">
<div class="loginbox">
<?php
if ($isOwner == "yes") {?>
<h3>Welcome <?php echo $u; ?>!</h3>
<?php
if ($isOwner == "yes") {?>
<p>Last online: <?php echo $lastsession;?> </p>
<br /><br />
<?php
}
?>
<button class="btn btn-default" href="logout.php">Log Out</button>
<?php
}
?>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<script src="js/ajax.js"></script>
</body>
<?php
include 'php_includes/footer.php';
?>
</html>
For some reason nothing is changing in the db when i hit submit, its so weird i am totally out of ideas...
But my knowledge is so limited that I can't see where the error lies and i am stuck.
Does anyone have an idea on how I could make this work?
Thanks in advance!
EQ
Why are you using a select query on users where you check on ID, Username and password. I assume every username has his own ID so you can just check on ID. Dont put password in the session.
change to:
<form action="" method="post">

Closing a session when a user navigates away from a site

I've got a login script that does not close the session when the user goes to another site or returns to the login page. My question is, how do I destroy the session when they navigate away from the site or outside of the directory? Would I need to add a timeout argument when the user starts the session? Would I need to use cookies instead of session?
login.php
require("../includes/header.php");
if($_SERVER["REQUEST_METHOD"] == "POST"){
$p_num = $_POST["username"];
$pwd = $_POST["password"];
$query = "SELECT * FROM $user_table";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_assoc($result)){
$user_id = "{$row['user_id']}";
$user_name = "{$row['user_name']}";
$password = "{$row['password']}";
$image = "{$row['image']}";
$email = "{$row['email']}";
$program = "{$row['program']}";
$role = "{$row['role']}";
if(($user_id == $p_num) && ($pwd == $password)){
$_SESSION["id"] = $user_id;
$_SESSION["user"] = $user_name;
$_SESSION["program"] = $program;
$_SESSION["pass"] = $password;
$_SESSION["image"] = $image;
$_SESSION["email"] = $email;
$_SESSION["role"] = $role;
header("Location: ../pages/instructor.php");
}
else{
header("Refresh: 1; URL=../index.php");
}
}
}
instructor.php
<?php require("../includes/header.php"); ?>
<title></title>
<link href="../css/style.css" rel="stylesheet/less" type="text/css">
<script src="../js/jquery.2.0.3.js"></script>
<script src="../js/script.js"></script>
<script src="../js/less-1.7.4.min.js"></script>
</head>
<body>
<div id="page">
<header>
<div id="logo" class="logo_bg"></div>
<div id="fsi_logo" class="logo_bg"></div>
</header>
<div id="main">
<div id="instructor">
<?php
echo "<img id=instructor_image src=" .$_SESSION["image"] .">";
echo "<h1>" .$_SESSION["user"] ."</h1>";
echo "<span><p>" .$_SESSION["program"] ."</p> - <h2>" .$_SESSION["role"] ."</h2></span>";
echo "" .$_SESSION["email"] ."";
?>
</div>
<div id="bleg">
<h1>BUILD SCENARIO</h1>
<h1>SEARCH SCENARIOS</h1>
<h1>VIEW SCENARIOS</h1>
</div>
<?php require("../includes/footer.html"); ?>
logout.php
session_start();
session_unset();
session_destroy();
script.js
$(window).on('beforeunload', function(e){
e.preventDefault();
ajax = new XMLHttpRequest();
ajax.open("../php/logout.php", "POST", true);
ajax.send();
})
Do it with javascript
window.onbeforeunload = function (e) {
e.preventDefault(); //Not even sure what the default action does, but oh well
ajax = new XMLHttpRequest();
ajax.open("killsession.php","POST",true);
ajax.send();
}
killsession.php will of course be where the session is killed
Write a jquery/JS event handler for unload doc and send a request to ExpireSession.php expiring the session
As said "It depends on what constitutes "leaving""
$count = $_SESSION['count'];
if($count === 1) {
unset ($_SESSION['count']);
}
else (empty($_SESSION['count'])) {
$_SESSION['count'] = 1;
}

Categories