PHP file executes twice - php

I have a php website which get executed twice. When I say echo hello; in config.php file it shows "hello" twice I checked all loops but I don't understand why this happens, anyone please help me out of this.
I'm really very thankful to him/her...
Here is the screenshot
My Website
Thank you in advance

<?
session_start();
//include "config.php";
require("config.php");
global $c,$loggedin;
include "data.php";
global $config;
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo $config["site_name"]; ?></title>
<link href="templates/ModernBlue/css/global.css" rel="stylesheet" type="text/css" />
<link href="templates/ModernBlue/css/site.css" rel="stylesheet" type="text/css" />
<!--33brushes-styles--><link href="templates/ModernBlue/33brushes-styles/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="templates/ModernBlue/33brushes-styles/css/33brushes-custom.css" rel="stylesheet" type="text/css" />
<link href="templates/ModernBlue/33brushes-styles/css/jquery.onebyone.css" rel="stylesheet" type="text/css">
<link href="templates/ModernBlue/33brushes-styles/css/example1.css" rel="stylesheet" type="text/css">
<link href="templates/ModernBlue/33brushes-styles/css/animate.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Cuprum:400,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Raleway:400,600' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
<link rel="icon" href="favicon.png" type="image/png"/><!--33brushes-styles-->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.9.1.custom.min.js"></script>
<link href="templates/ModernBlue/css/evolutionscript/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script type="text/javascript" src="js/evolutionscript.js"></script>
<script type="text/javascript" src="js/l2blockit.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/bootstrap.min.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/bootstrap_custom.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/jquery.onebyone.min.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/jquery.touchwipe.min.js"></script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#slider').oneByOne({ className: 'oneByOne1', easeType: 'random', slideShow: true, slideShowDelay: 5000 }); }); </script>
<? if($_GET['r']){
header('location:cmrf/register.php?r='.$_GET['r']) ;
} ?>
</head><body>
<div class="wrapper"><div class="header-top"> <div class="container">
<div class="logo fl-l"></div>
<div class="header-right"> <div class="top-navi">
<ul class="nav nav-pills fl-l">
<li>Member Login</li>
<li>New Participant List</li>
</ul>
</div>
<div class="navigation">
<ul class="nav nav-pills" style="margin-left: 2px;">
<li>Home</li>
<li> LOGIN </li>
<li>REGISTER </li>
<li> SYSTEM</li>
<li>IDEOLOGY</li>
<li>BONUS</li>
<li>NEWS</li>
<li>CONTACT</li> </ul>
<div class="clear"></div> </div> </div> <!--end header-right--> </div> <!--end container--></div> <!--end header-top-->
<div class="slider-container"> <div class="container"> <div class="slider-content">
<div id="slider">
<div class="oneByOne_item">
<div class="slider-fl1">
<h2>Help To Earn</h2>
<p>The first way to get financial help from PHP Community is by providing help. Currently you will be making 35% in 30 days, calculated daily from the day you pledged to help Someone </p>
</div>
<!--end slider-fl1--> <img src="templates/ModernBlue/33brushes-styles/img/slide1-1.png" class="slide1-1" alt=""></img>
</div> <div class="oneByOne_item">
<div class="slider-fl1">
<h2>OUR GREAT PLAN</h2>
<p>The goal of PHP is today you provide help, tomorrow you may request help when you require for whatever amount. The calculation is just as preventive measure for the parasites of the community from abusing our system.
</p>
</div><!--end slider-fl1--> <img src="templates/ModernBlue/33brushes-styles/img/slide2-1.png" class="slide2-1" alt=""></img>
</div> <div class="oneByOne_item">
<div class="slider-fl1">
<h2>Introduce to Earn !</h2>
<p>Any member can be an introducer, each time your introduced member provide any amount of help, as a normal member you will earn 10% of the amount.
</p>
</div><!--end slider-fl1--> <img src="templates/ModernBlue/33brushes-styles/img/slide3-1.png" class="slide3-1" alt=""></img>
</div> </div>
<div class="clear"></div>
<div class="more-ways">Achieve Success with EASY!!</div> </div> <!--end slider-content-->
</div> <!--end container--> </div> <!--end slider-container-->
<!-- End Content -->
</div><!--end main-content--> <div class="footer-top"> <div class="container">
<div class="span6">
Home •
Login •
Register •
System •
Ideology •
Bonus •
Contact </div>
<div class="social-logos"><br>Copyright © 2016/17 <? echo $config["site_name"]; ?> All rights reserved. </div> </div> <!--end container--></div>
</div> <!--end wrapper--></body>
</html>
config.php
<?php
$dhost = "localhost"; // Isi dengan localhost
$dusername = ""; // database user
$dpassword = ""; // database pass
$ddatabase = ""; // database name
date_default_timezone_set("Africa/Johannesburg");
$con = mysql_connect($dhost, $dusername, $dpassword) or die("Cannot Connect");
mysql_select_db($ddatabase, $con);
if($_COOKIE["usNick"] and $_COOKIE["usPass"])
{
$q = mysql_query("SELECT * FROM tb_users WHERE username='{$_COOKIE['usNick']}' AND password='{$_COOKIE['usPass']}'") or die(mysql_error());
if(mysql_num_rows($q) == 0)
{
$_COOKIE['usNick'] = false;
$_COOKIE['usPass'] = false;
} else {
$loggedin = 1;
$r = mysql_fetch_array($q);
}
}
$da = date("j");
$user=$_COOKIE['usNick'];
mysql_query("UPDATE tb_jual SET status='Success' WHERE saldo='0'") or die(mysql_error());
mysql_query("UPDATE tb_beli SET status='Success' WHERE verify!=''") or die(mysql_error());
$skrg=time();
$query="select * from tb_beli where dpro < '$skrg' and status='Success' and spro=''";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
$namauser=$row["username"];
$duitc=$row["jpro"];
$idlo=$row["id"];
mysql_query("UPDATE tb_users SET money=money+'$duitc' WHERE username='$namauser'") or die(mysql_error());
mysql_query("UPDATE tb_beli SET spro='berhasil' where id='$idlo'") or die(mysql_error());
}
/*****************GH match with balance*********************/
echo 'hellooooooooooooo';
include_once("function.php");
$pak = $_GET['pak'];
$saldo_arr = array(1,2,3,4,5,6,7,8,9,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,150,200,250,300,350,400,450,500,600,700,800,900,1000);
for($i=0;$i<count($saldo_arr);$i++)
{
$saldooo = $saldo_arr[$i];
$tablaa = mysql_query("SELECT * FROM tb_jual where status='pending' and saldo!='0' and saldo='$saldooo' and username!='$kurirz' ORDER BY id ASC limit 0,1");
$registroo = mysql_fetch_array($tablaa);
$saldo_match = 0;
$kurir=$registroo["username"];
$biaya=$registroo["saldo"];
$idnya=$registroo["id"];
$pakt=$registroo["paket"];
$skrg=time();
$exp=$skrg+245600;
$sms = mysql_query("SELECT * FROM tb_beli where status='pending' and referer='' and saldo='$biaya' ORDER BY id ASC limit 0,1");
while($registroo1 = mysql_fetch_array($sms)){
$saldo_match = 1;
$kurirz=$registroo1["username"];
$idnyaz=$registroo1["id"];
$pake=$registroo1["paket"];
mysql_query("UPDATE tb_beli SET referer='$kurir', iddb='$idnya', exp='$exp' where status='pending' and id='$idnyaz' ") or die(mysql_error());
mysql_query("UPDATE tb_jual SET status='Waiting for transfer' where id='$idnya'") or die(mysql_error());
}
}
$pak1 = $pak/100;
/* for($n=0;$n<count($saldo_arr);$n++)
{
$saldoe = $saldo_arr[$n];
$tablae = mysql_query("SELECT * FROM tb_jual where status='pending' and saldo!='0' and saldo='$saldoe' and username!='$kurirz' ORDER BY id ASC limit 0,1");
$registroe = mysql_fetch_array($tablae);
//echo $biaya; */
if($saldo_match == 0){
$number = $pak1;
//echo $number.'hii';
if($number>1 && $number<10)
{
$n = 2;
}
elseif($number>10 && $number<100)
{
$n=5;
}
elseif($number>100 && $number<1000)
{
$n=5;
}
$multiple = 1;
$values = get($number, $n, $multiple);
print_r($values);
for($v=0;$v<count($values);$v++){
}
/* $sal = $values[$v];
$query_notmatch = mysql_query("SELECT * FROM tb_beli where status='pending' and referer='' and saldo='$sal' and existed='0' order by id ASC");
$registroo2 = mysql_fetch_row($query_notmatch);
$kurirz=$registroo2[1];
$idnyaz=$registroo2[0];
$pake=$registroo2[5];
$saldoz=$registroo2[6];
if(!$saldoz)
{
$saldoz=0;
echo $saldoz.'hii';
}
$skrg=time();
$exp=$skrg+245600;
if($saldoz!=$sal){
echo "hello123";
$pakett= $sal*100;
$user=$_COOKIE["usNick"];
$nama=$registroo["nama"];
$email=$registroo["email"];
$bank=$registroo["bank"];
$norek=$registroo["norek"];
$phone=$registroo["phone"];
$paket=$sal*100;
$laip = $_SERVER['REMOTE_ADDR'];
$eltiempo=time();
$query = "INSERT INTO tb_jual (username, bank, norek, nama, paket, saldo, phone, email, status, date, ip) VALUES('$user','$bank','$norek','$nama','$paket', '$sal', '$phone', '$email', 'pending','$eltiempo','$laip')";
mysql_query($query) or die(mysql_error());
echo $paket;
mysql_query("UPDATE tb_jual SET status='pending', paket='$pakett', saldo='$sal' where id='$idnya'") or die(mysql_error());
}
else{
mysql_query("UPDATE tb_beli SET referer='$kurir', iddb='$idnya', exp='$exp' , existed='1' where status='pending' and id='$idnyaz'") or die(mysql_error());
mysql_query("UPDATE tb_jual SET status='Waiting for transfer', saldo='$sal' where id='$idnya'") or die(mysql_error());
} */
}
/* } */
/*********************************/
$skrg=time();
$queryf="select * from tb_beli where exp < '$skrg' and exp != '' and status='pending'";
$result=mysql_query($queryf);
while ($rowf=mysql_fetch_array($result)) {
$namaibu=$rowf["username"];
$idbu=$rowf["id"];
$idkol=$rowf["iddb"];
$paket=$rowf["paket"];
mysql_query("DELETE from tb_beli WHERE id='$idbu'") or die(mysql_error());
mysql_query("UPDATE tb_users SET suspend='1' WHERE username='$namaibu'") or die(mysql_error());
mysql_query("UPDATE tb_jual SET status='pending', date='$skrg' WHERE id='$idkol'") or die(mysql_error());
/**************sms send match******************/
/* $sms = mysql_query("SELECT * FROM tb_beli where status='pending' and referer='' and paket='$paket' order by id ASC limit 0,1");
while($sms_values = mysql_fetch_array($sms))
{
$phone=$sms_values['phone'];
$namew= $sms_values['username'];
$username_sms = urlencode("Bluejack");
$password_sms= urlencode("YUS#7860");
$api_id = urlencode("3610145");
$to = urlencode($phone);
$message = urlencode("Dear $namew,
Your order on PHP Community Stokvel is out, Please log in your system for further instructions
,Thank you
");
?>
<div class="sms">
<?php echo file_get_contents("http://www.mymobileapi.com/api5/http5.aspx?Type=sendparam&username=$username_sms&password=$password_sms&numto=$to&data1=$message");
?>
</div>
<? } *//******************End sms********************************/
}
$tablaqa = mysql_query("SELECT * FROM tb_config where item='bintanga'");
while ($registroqa = mysql_fetch_array($tablaqa)) {
$duitq=$registroqa["price"];
$tabla = mysql_query("SELECT * FROM tb_users where referals >=$reffq and jdb >=$duitq and ba=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='1', ba='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b1=b1+1 where username='$kurire'") or die(mysql_error());
}}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang2'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b1 >=$reffq and bi=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='2', bi='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b2=b2+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang3'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b2 >=$reffq and bu=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='3', bu='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b3=b3+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang4'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b3 >=$reffq and be=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='4', be='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b4=b4+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang5'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b4 >=$reffq and bo=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='5', bo='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b5=b5+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang6'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b5 >=$reffq and bz=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='6', bz='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b6=b6+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang7'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b6 >=$reffq and bx=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='7', bx='ok' where id='$idnya'") or die(mysql_error());
}
}
?>

Related

SQL failing in one page on some machines

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:

How to delete MySql database row with PHP button

I have an backend website setup that displays all the users on my site in an organised table, I should be able to edit and delete the users from the php page. However I cannot get the delete function to work, here is the code.
Data_Display.php
<?php
include('session.php');
?>
<?php include ("db.php"); ?>
<?php
$sql = "SELECT * FROM username ORDER BY UserNameID DESC";
$query = mysql_query($sql) or die(mysql_error());
if (isset($_GET['UserNameID'])) {
$id = mysql_real_escape_string($_GET['UserNameID']);
$sql_delete = "DELETE FROM users WHERE id = '{$UserNameID}'";
mysql_query($sql_delete) or die(mysql_error());
header("location: data_display.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" type="image/ico" href="favicon.ico">
<title>Network TV - All Records</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body >
<div class="container">
<div class="content">
<h1>Network TV Users and User control panel</h1>
<br>
<div class="toolbar">
Add New Person
Home
</div>
<br>
</div>
</div>
<div class="container">
<div class="content">
<?php if (mysql_num_rows($query)) { ?>
<?php while ($rows = mysql_fetch_assoc($query)) { ?>
<div class="separator"></div>
<h2><b>User reference:</b> <?php echo $rows['UserNameID']; ?></h2>
<h2><b>Name:</b><?php echo $rows['name']; ?></h2>
<h2><b>Email address:</b> <?php echo $rows['email']; ?></h2>
<h2><b>Gender:</b> <?php echo $rows['sex']; ?></h2>
<h2><b>Profile Picture:</b> <?php echo $rows['imagelink']; ?></h2>
<div class="toolbar">
Edit
Delete
</div>
<?php } /* End Loop */ ?>
<div class="separator"></div>
<?php } else { ?>
<div class="separator"></div>
<h2>There are no records to display</h2>
<div class="separator"></div>
<?php } /* End Rows Checking */?>
</div>
</div>
<div class="container">
<br>
<br>
<br>
<br>
<br>
</div>
<script>
function confirmDelete ( message, url )
{
var confirmation = confirm ( message );
if ( confirmation == true ) {
window.location = url;
} else {
return false;
}
}
</script>
</body>
</html>
Session.php
<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "Oliver");
// Selecting Database
$db = mysql_select_db("users", $connection);
if(!isset($_SESSION)){session_start();}
// Storing Session
$user_check=$_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select username from username where username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: home.php'); // Redirecting To Home Page
}
?>
db.php
<?php
$connection = mysql_connect('localhost', 'root', 'Oliver');
mysql_select_db('users', $connection) or die(mysql_error());
?>
Information
When I click the delete button in data_display.php, I do receive the javascript alert to confirm that I do want to delete the user from the database, but nothing actually happens.
if (isset($_GET['recordId'])) {
$id = mysql_real_escape_string($_GET['recordId']);
$sql_delete = "DELETE FROM users WHERE id = '{$id}'";
mysql_query($sql_delete) or die(mysql_error());
header("location: data_display.php");
exit();
}
You are sending recordId as parameter.

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">

query was empty in search php

Im trying to make this search with a select option to select which site, or all the sites.
When i click on all sites it works. When i click on "4shared" it works. But when i click "putlocker" i get this. Query was empty.
I really dont know what i did wrong
<?php
include"inc/connect.php";
include"inc/functions.php";
error_reporting(0);
if(isset($_GET['s']) && $_GET['s'] != ""){
$s = $_GET['s'];
$w = $_GET['w'];
if($w == 'all'){
$sql = "SELECT * FROM result WHERE (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == 'Sockshare'){
$sql = "SELECT * FROM result WHERE website='Sockshare' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == 'Putlocker'){
$sql == "SELECT * FROM result WHERE website='Putlocker' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == '4shared'){
$sql = "SELECT * FROM result WHERE website='4shared' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == 'Rapidshare'){
$sql = "SELECT * FROM result WHERE website='Rapidshare' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}
$query = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($query);
if($count > 1){
while($row = mysql_fetch_array($query)){
$name = $row["name"];
$details = $row["details"];
$url = $row["url"];
$results .= '
<div id="stitle">' .$name. '</div>
<div id="details">' .$details. '</div>
<div id="url"><a target="_blank" href="' .$url. '">' .$url. '</a></div>';
}
} else {
$results = 'Nothing found!';
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Findrfile.com - Putlocker Search | Sockshare search | Mediafire Search</title>
<link href='http://fonts.googleapis.com/css?family=Orienta' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="main.css" />
</head>
<body>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<?php include"header.php"; ?>
<div id="spacer"></div>
<?php include"litsearch.php"; ?>
<div id="nuresults"><span class="blue"><?php echo $count; ?> Results found</span></div>
<div id="spacerx"></div>
<div id="wrapper">
<div id="spacerx"></div>
<div id="content">
<?php echo $results; ?>
<div class="clear"></div>
</div>
<div id="spacerx"></div>
<div id="spacer"></div>
</div>
<?php include"footer.php"; ?>
</body>
</html>
You have $sql == "SELECT * FROM result WHERE website='Putlocker' AND (name LIKE '%".$s."%') OR (keyword LIKE '%".$s."%')"; notice the ==, this is a comparison operator so it won't set a value to $sql
I think that may be your issue.
Change
while($row = mysql_fetch_array($query)){
to
while($row = mysql_fetch_assoc($query)){
Because you use associative array.
$name = $row["name"];
$details = $row["details"];
$url = $row["url"];
If you want to use
while($row = mysql_fetch_array($query)){
like:
$name = $row[0];
$details = $row[1];
$url = $row[2];
Am I wrong?
ALSO:
you check if $_GET["s"] is set but you do not check $_GET["w"]

Deducting Numbers From Database Php

I have this table venue which consists of:
idVenue
name
description
room_size
What i'm trying to do is
ie. Venue A can have 5 person.
In DB, i have a room_size field which is 5.
So everytime a person is being selected to Venue A, just deduct 1 from the total (which is 5 for now). Once it reaches 0, then don't show out the Venue.
I heard flagging is possible, how do i actually go upon doing that?
Here's the code:
do_select.php
<?php
session_start();
if(($_SESSION['role'])!='Admin'){
echo "You have not logged in as admin yet.<br/>";
echo "Please <a href='login.php'>login</a>.";
exit;
}
?>
<?php
//member id
$id = $_POST['id'];
$idimplode = implode (", ", $id);
$idexplode= explode(", ", $idimplode);
//accept, reject
$select=$_POST['select'];
$comma = implode (", ", $select);
$comma1 = explode(", ", $comma);
$check =($idexplode);
//class id
$idc = $_POST['idc'];
include('dbconfig.php');
for($i=0;$i< sizeof($comma1);$i++)
{
if($comma1[$i]=="accept")
{
//Select Query if status is accept
$query="UPDATE attendance SET status='accept' WHERE Member_idMember ='$check[$i]' and Class_idClass='$idc'" ;
$result = mysqli_query($link, $query) or die(mysqli_error($link));
}
else
{
//Select Query if status is reject
$query2="UPDATE attendance SET status='reject' WHERE Member_idMember ='$check[$i]' and Class_idClass='$idc'" ;
$result1 = mysqli_query($link, $query2) or die(mysqli_error($link));
}
}
//select members based on status
$query3 = "SELECT * FROM member m, attendance a, class c
WHERE a.Member_idMember = m.idMember
AND a.Class_idClass = c.idClass
AND a.status = 'accept'
AND a.Class_idClass = '$idc'
";
$result3 = mysqli_query($link, $query3) or die (mysqli_connect_error($link));
//select query to get the class dates
$query4 = "SELECT day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11, day12 FROM class
WHERE idClass = '$idc'";
$result4 = mysqli_query($link, $query4) or die (mysqli_connect_error($link));
//select query to get venue id
$query6 = "SELECT DISTINCT idVenue FROM venue";
$result6 = mysqli_query($link, $query6) or die (mysqli_connect_error($link));
while($row = mysqli_fetch_array($result4, MYSQL_NUM))
{
$day[] = implode(", ", $row);
}
$iday = implode(", ", $day);
$eday = explode(", ", $iday);
while($row = mysqli_fetch_array($result6, MYSQL_NUM))
{
$ven[] = implode(",", $row);
}
$iven = implode(", ", $ven);
$even = explode(", ", $iven);
$date = ($eday);
$venue= ($even);
?>
<!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=iso-8859-1" />
<title>ST JOHN</title>
<link rel="stylesheet" type="text/css" href="main.css" />
<script language="JavaScript" type="text/javascript">
</script>
</head>
<body>
<!-- Begin Wrapper -->
<div id="wrapper">
<!-- Begin Header -->
<div id="header">
<img src="Image/1.jpg" width="900" height="100" />
</div>
<!-- End Header -->
<!-- Begin Navigation -->
<div id="navigation">
<img src="Image/4.png" width="30" height="30" > Welcome!!! <br>;
Logout;
</div>
<!-- End Navigation -->
<!-- Begin Faux Columns -->
<div id="faux">
<!-- Begin Left Column -->
<div id="leftcolumn">
<center><img src="Image/2.jpg" width="150" height="100" /><br>
<ul>
<li>About Us</li>
<li>Public Courses</li>
<li>Cadet Affairs</li>
<li>Events</li>
<li>Contact Us</li>
</ul></center>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<h1>Assign Venue</h1><br/>
<?php
echo"<table border='1'>";
echo"<th>Name</th>";
echo"<th>Signup Datetime</th>";
echo"<th>Status</th>";
echo"<th>Class</th>";
echo"<th>Venue</th>";
while($row=mysqli_fetch_assoc($result3))
{
$idc=$row['idClass'];
$id=$row['idMember'];
$Name = $row['name'];
$Status = $row['status'];
$Signup_datetime = $row['signup_datetime'];
$class=$row['Class_idClass'];
$idt=$row['Time_Slot_idTime_Slot'];
echo "<form method='post' action='assign_venue.php'>";
echo "<tr>";
echo "<td>".$Name."</td>";
echo "<td>".$Signup_datetime."</td>";
echo "<td>".$Status."</td>";
echo "<td>".$class."</td>";
echo "<input name='idc' type='hidden' value= '$idc'/>";
echo "<input name='id[]' type='hidden' value= '$id'/>";
echo "<td><select id ='idv[]' name='idv[]'>";
for ($v=0; $v <count($venue); $v++)
{
for ($d=0; $d <count($date); $d++)
{
//select query to determine which are the dates that are in conflict with each other
$sql = "SELECT * FROM venue v, class c, attendance a
WHERE a.Venue_idVenue = v.idVenue
AND a.Class_idClass = c.idClass
AND v.idVenue = '$venue[$v]'
AND (day01='$date[$d]' OR day02='$date[$d]' OR day03='$date[$d]' OR day04='$date[$d]' OR day05='$date[$d]' OR day06='$date[$d]'
OR day07='$date[$d]' OR day08='$date[$d]' OR day09='$date[$d]' OR day10='$date[$d]' OR day11='$date[$d]' OR day12='$date[$d]')
AND c.Time_Slot_idTime_Slot = '$idt'";
$rs = mysqli_query($link, $sql) or die (mysqli_connect_error($link));
while ($row = mysqli_fetch_assoc($rs))
{
//if there are no conflict, then display the venue
if (mysqli_num_rows($rs) != 0)
{
$ve[]= $row['idVenue'];
break;
}
}
}
}
$if = implode(",", $ve);
$ef = explode(",", $if);
$ve = ($ef);
for ($f=0; $f <count($ve); $f++)
{
//select query to get venue id and name
$sql1 = "SELECT * FROM venue WHERE idVenue != '$ve[$f]'";
$rs1 = mysqli_query($link, $sql1) or die (mysqli_connect_error($link));
}
while($row = mysqli_fetch_assoc($rs1))
{
//display venue id and venue name
$idv=$row['idVenue'];
$name=$row['name'];
echo"<option name='idv[]' value='$idv'>$name</option> ";
}
echo "</select>";
}
echo "</table>";
echo "<td><input type='submit' value= 'Submit'>
</form>";
mysqli_close($link);
?>
<div class="clear"></div>
</div>
<!-- End Right Column -->
<div class="clear"></div>
</div>
<!-- End Faux Columns -->
<!-- Begin Footer -->
<div id="footer">
<center><p>Copyright© St. John Ambulance Singapore # 420, Beach Road, Singapore 199582 Tel: 6298 0300 Fax: 6296 5797click here for map</p></center>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
you should have another field called current_occupancy
When you create the row
update venue set current_occupancy = room_size where id = <idOfVenue>
Then when someone selects:
update venue set current_occupancy = current_occupancy - 1 where id = <idOfVenue>
And only show fields that match
select * from venue where current_occupancey > 0 <whatever else>

Categories