Age Verify code kicking people out of to old? - php

my code is letting people in if there above 19 but also if your to old its not letting you enter why is this ? I had a person try to enter my site today with 1958 and got kicked out yet i can enter 1989 and it works fine
index page
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>510 Vapour</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/responsive.css">
<link rel="stylesheet" href="css/animate.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
</head>
<div class="js">
<body>
<!-- Preloader section -->
<div id="preloader"></div>
<!-- Preloader section -->
<div class="container">
<!-- AccessBox section -->
<div id="accessbox"class="animated bounceInDown"> <img class="profile-img" src="images/logo.png" />
<h2 class="text-center">Please enter your date of birth</h2>
<!-- Form section-->
<form action="php/access.php" method="post" class="access-form">
<input type="text" name="yy" class="access-input-lg" placeholder="2016" required autofocus>
<input type="text" name="mm" class="access-input" placeholder="05">
<input type="text" name="dd" class="access-input" placeholder="10">
<input type="submit" name="submit"class="access-btn" value="OK" >
<div id="remember" class="checkbox text-center">
<label class="text-center">
<input type="checkbox" value="remember-me">
Remember me </label>
</div>
</form>
<!-- Form section-->
<h1 class="text-center"><i class="fa fa-exclamation-triangle red"></i> You must be 19+ to enter this site </h1>
<p class="text-center">By ENTERING, you are consenting to your Province's Smoking Laws. You may be required to show a valid government issued Photo ID indicating your date of birth at time of delivery or at the Post Office.</p>
</div>
<!-- AccessBox section -->
</div>
<!-- /container -->
<!-- JS files-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Pre Loader-->
<script type="text/javascript">
jQuery(document).ready(function($) {
$(window).load(function(){
$('#preloader').fadeOut('slow',function(){$(this).remove();});
});
});
</script>
</body>
</div>
</html>
access.php
<?php
$minAge = 19;
if(isset($_POST['submit'])){
if(strlen($_POST['mm'])==1)
$month = '0'.$_POST['mm'];
else
$month = $_POST['mm'];
$agevar = $_POST['yy'];
$age = strtotime($agevar);
$nineteen = strtotime("-" . $minAge . " years");
if($age && $nineteen && $age <= $nineteen){
header('Location: https://www.510vapour.com/main');
}
else{
header('Location: ../error.html');
}
}
?>

You can use DateTime objects to calculate the person's exact age and select the appropriate action based on that.
Using year-month-day format when constructing the object should work regardless of the number of digits provided for year, month or day.
$birthdate = new DateTime($_POST['yy'].'-'.$_POST['mm'].'-'.$_POST['dd']);
$now = new DateTime;
$age = $birthdate->diff($now);
if ($age->y >= $minAge){
header('Location: https://www.510vapour.com/main');
} else {
header('Location: ../error.html');
}

Here's an easier solution :
if (time() < strtotime('+19 years', strtotime($dob))) {
//User is under 19 years of age
header('Location: ../error.html');
}else{
header('Location: https://www.510vapour.com/main');
}
Valid $dob
1979-02-21 or 21 Feb 1986
You can also use a jQuery script to check user's age.

Related

I am attempting to create a php search bar that directs to larger search engines. It isn't working and I don't understand how to solve it.

webdevprocess.html
[This page is used solely for the search bar at the bottom of the page. Any search term can be entered and then a search engine can be selected from the drop down menu.]
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Web Development Process</title>
<meta name="Web Development Process" content="Simple Responsive Template is a template for responsive web design. Mobile first, responsive grid layout, toggle menu, navigation bar with unlimited drop downs, responsive slideshow">
<meta name="keywords" content="">
<!-- Mobile viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<!-- CSS-->
<!-- Google web fonts. You can get your own bundle at http://www.google.com/fonts. Don't forget to update the CSS accordingly!-->
<link href='http://fonts.googleapis.com/css?family=Droid+Serif|Ubuntu' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="js/flexslider/flexslider.css">
<link rel="stylesheet" href="css/basic-style.css">
<!-- end CSS-->
<!-- JS-->
<script src="js/libs/modernizr-2.6.2.min.js"></script>
<script type="text/javascript" src="mypiechart.js"></script>
<script type="text/javascript" src="canvasjs.min.js"></script>
<!-- end JS-->
</head>
<body>
<body id="home">
<!-- header area -->
<header class="wrapper clearfix">
<div id="banner">
<div id="logo"><img src="images/logo.jpg" alt="logo"></div>
</div>
<!-- main navigation -->
<nav id="topnav" role="navigation">
<div class="menu-toggle">Menu</div>
<ul class="srt-menu" id="menu-main-navigation">
<li class="current">Home page</li>
<!-- <li>Internal page demo</li> -->
<li>Client/Server Technology
<ul>
<li>
Client/Server Technology
</li>
<li>Domain Names and Hosting</li>
</ul>
</li>
<li>
JavaScript Pages
<ul>
<li>Web Development Process</li>
</ul>
</li>
<li>
PHP Pages
</li>
</ul>
</nav><!-- end main navigation -->
</header><!-- end header -->
<!-- main content area -->
<div id="main" class="wrapper">
<!-- content area -->
<section id="content" class="wide-content">
<div class="row">
<h1>What Is The Web Development Process?</h1>
<p>A web development process,or web design and development process, is a systematic process or methodology, used tp desgn and build web sites. Just as planing goes into the design
of cars, buildings, or homes, so too is the planning and design and development process required for web sites. A good process helps ensure customer requirements are delivered in a quality
, timely and cos-effective manner.</p>
<h1>SDLC and Project Management</h1>
<p>The web design and development process can be thought of as a type of software development life cycle (SDLC) and project management methodology. The waterfall model depicted
below is a long-standing, traditional SDLC that is characterized by sequential steps. Agile is a newer method that is intended to more quickly respond to changing customer and
product requirements using an incremental process with frequent releases and customer feedback.</p>
<h3>Traditional Waterfall SDLC Methodology (PNG image)</h3>
<p><img src="waterfall.png" alt="Waterfall SDLC"></p>
<p>Source: WikiPedia</p>
<h3>Agile Methodology (GIF image)</h3>
<p><img src="images/agile.png" alt="Agile Methodology"></p>
<h3>Web Development Phases (HTML/JavaScript image)</h3>
<div id="chartContainer" style="height: 450px; width: 95%;"></div>
<script>
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title: {
text: "Web Development Process"
},
data: [{
type: "pie",
startAngle: 240,
yValueFormatString: "##0.00\"%\"",
indexLabel: "{label} {y}",
dataPoints: [
{y: 20.00 , label: "Testing"},
{y: 10.00, label: "Promotion"},
{y: 25.00, label: "Analysis"},
{y: 20.00, label: "Design"},
{y: 25.00, label: "Construction"}
]
}]
});
chart.render();
}
</script>
<br>
<form action="search.php" method="get">
<table>
<tr>
<th colspan="2">Search Sites</th>
</tr>
<tr>
<td>Site to Search:</td>
<td>
<select name="site">
<option value="google">Google Web
<option value="googlei">Google Images
<option value="duck">DuckDuckGo
<option value="wiki">WikiPedia
</select>
</td>
</tr>
<tr>
<td>Search term(s):</td>
<td>
<input type="text" name="terms" size="25" maxlength="25">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit" class-"centercell">
</td>
</tr>
</table>
</form>
<br>
</div><!-- end row -->
</section><!-- end content area -->
</div><!-- #end div #main .wrapper -->
<!-- footer area -->
<footer>
<div id="colophon" class="wrapper clearfix">
Author: Janae Roland
</div>
<!--You can NOT remove this attribution statement from any page, unless you get the permission from prowebdesign.ro--><div id="attribution" class="wrapper clearfix" style="color:#666; font-size:11px;">Site built with Simple Responsive Template by Prowebdesign.ro</div><!--end attribution-->
</footer><!-- #end footer area -->
<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.9.0.min.js">\x3C/script>')</script>
<script defer src="js/flexslider/jquery.flexslider-min.js"></script>
<!-- fire ups - read this file! -->
<script src="js/main.js"></script>
</body>
</html>
search.php
[This program is supposed to send the search terms entered to large search engines (google,google images,duck duck go,wikipedia) but I am receiving a syntax error, "
Notice: Use of undefined constant FIlTER_SANITIZE_STRING - assumed 'FIlTER_SANITIZE_STRING' in /home/jsroland/public_html/search.php on line 13
Warning: filter_input() expects parameter 3 to be long, string given in /home/jsroland/public_html/search.php on line 13"]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Rock,Paper,Scissors">
<meta name="description" content="A function that sends data to large search engines,through the WebDev search bar.">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Search</title>
</head>
<body>
<?php
$site = substr(filter_input(INPUT_GET, 'site', FIlTER_SANITIZE_STRING),0,8);
$terms = substr(filter_input(INPUT_GET, 'terms', FILTER_SANITIZE_STRING),0,25);
if ($site == "google")
header('Location: http://www.google.com/#g=' . $terms);
else if ($site == "googlei")
header('Location: http://www.google.com/search?tbm=isch&g=' . $terms);
else if ($site == "duck")
header('Location: https://duckduckgo.com/?q=&ia=web' . $terms);
else if ($site == "wiki")
header('Location: https://en.wikipedia.org/wiki/' . $terms);
?>
</body>
</html>
The minimal correct urls for search engines would be as follows:
for general Google search: https://www.google.com/search?q='<search
terms>',
for Google image search:
https://www.google.com/search?tbm=isch&q='<search terms>',
for
DuckDuckGo: https://duckduckgo.com/?ia=web&q='<search terms>',
for
Wikipedia: https://en.wikipedia.org/wiki/<search terms>.
where <search terms> are the terms to search for.
Please also mind quotation marks in the first three cases. The final code would look something like this.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Rock,Paper,Scissors">
<meta name="description" content="A function that sends data to large search engines,through the WebDev search bar.">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Search</title>
</head>
<body>
<?php
$site = substr(filter_input(INPUT_GET, 'site', FIlTER_SANITIZE_STRING),0,8);
$terms = substr(filter_input(INPUT_GET, 'terms', FILTER_SANITIZE_STRING),0,25);
if ($site == "google")
header("Location: https://www.google.com/search?q='$terms'");
else if ($site == "googlei")
header("https://www.google.com/search?tbm=isch&q='$terms'");
else if ($site == "duck")
header("Location: https://duckduckgo.com/?ia=web&q='$terms'");
else if ($site == "wiki")
header("Location: https://en.wikipedia.org/wiki/$terms");
?>
</body>
</html>

How to do <title> dynamic in PHP

I have a little template and in this template I have a query from database.
The name of the page is test.php and the code is:
This is the main page where i echo the content is named test.php
<?php include "components/header.php"; ?>
<div class="container">
<!-- Jumbotron -->
<?php
if (isset($_GET['user']))
{
$user = $_GET['user'];
}
else
{
die("Not found");
}
$result = mysqli_query($con, "SET NAMES utf8");
$query = "SELECT * FROM users WHERE fk_music=".$user;
$res = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($res);
echo $row['text'];?>
</div>
<?php include "components/footer.php"; ?>
Now with the echo $row['text'] I have to echo all the content from the page, and in header.php are the data like <html><header><title></title></header> etc. How can I put a title foreach data from database dynamic?
There is the code from header.php
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>???</title>
<!-- Bootstrap core CSS -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<link rel="stylesheet" href="/css/media-queries.css">
<link rel="stylesheet" href="/style.css">
<!--Hover categorii -->
<script src="/js/hover.js"></script>
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="/../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
Now in database i have two rows id of the post and the row named text where is stored the HTML of all the page
Here is an example with content existing in row['text']
<p class='style-title'>HERE IS THE THE TEXT I WANT TO PUT IT IN <title> </p>
<div class='jumbotron'>
<img class='img-responsive' src='/img/img.png'/>
</div>
<div class='row'>
<div class="col-lg-10 ">
<img class='img-responsive' src='/img/50.png' align='left' />
<p class='some-class'>Lorm ipsum</p>

Chrome loading the contents of a PHP file into a CSS file

My website loads perfectly on Firefox, but the CSS disappears completely on Chrome (although the html loads).
According to the console, this seems to be because Chrome is loading the contents of index.php into main.css and bannerTest.css like so:
On Firefox, however, it loads the CSS as expected:
Things I have tried that did not work:
clearing my history/cache/cookies
adding text/css to the tags. All this did was make the text render a
little weirdly on Firefox.
css and html validation. I fixed all the semi-colons and such. Still doesn't work.
What's the problem? I can't even figure out what steps to take to investigate what's going on more deeply, let alone figure out the problem itself. No errors are printed to the console as far as I can tell.
Here is index.php:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Study</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="css/bannerTest.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
<style>
/**
* The banner assumes a margin of 0px, but is not included
* in banner.css to avoid collisions with other themes and
* admin bars.
*/
body {
margin:0px;
}
</style>
<link rel="icon" type="image/ico" href="favicon.ico">
</head>
<body>
<?php
//Connect to MySQL database.
$host = "127.0.0.1";
$user = "root";
$password = "password";
$database = "database";
$r = mysql_connect($host, $user, $password);
if (!$r) {
echo "Could not connect to server.\n";
trigger_error(mysql_error(), E_USER_ERROR);
}
$query = "CREATE DATABASE IF NOT EXISTS " . $database;
mysql_query($query);
#mysql_select_db($database) or die("Unable to select database.");
$query="CREATE TABLE IF NOT EXISTS `groupcodes` (`groupcode` int(10) PRIMARY KEY, `usercode` int(10))";
mysql_query($query);
$userid = "";
?>
<div id="banner">
<div id="u-header-container">
<div class="container">
<div class="row-fluid">
<div id="home-link-container">
<a id="home-link" href="http://csue.edu/">
<span id="wordmark">U</span>
<span id="university">UNIVERSITY</span>
</a>
</div>
</div>
</div>
</div>
<div id="database-container">
<header>
<a href="index.php">
<h4 id="logo">Computing Systems</h4>
<h1 id="study_logo">Study</h1>
</a>
</header>
<div id="study">
<form method="post" id="consent-form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="wide-column">
<p>
By clicking the 'Acccept' button below, you hereby acknowledge the following:
</p>
<p>
I am 18 years of age or older, live in the United States, and have a Google Drive or Dropbox account.
I have read this form and decided that I will participate in the project described above.
Its general purposes, the particulars of involvement, and possible risks and inconveniences have
been explained to my satisfaction. I understand that I can withdraw at any time.
</p>
</div>
<input type="text" name="email_input">
<br>
<input type="submit" value="Begin Study">
</form>
</div>
</div>
</div>
</body>
</html>
You misdiagnosed the problem. It is due to visiting different URLs to load the HTML document rather then using different browsers. You just switched browsers at the same time as you switched URLs.
Look at the URL that is being loaded in your first image:
http://localhost/peergroup/index.php/css/main.css
In Chrome you must be visiting http://localhost/peergroup/index.php/ while in Firefox you are visiting http://localhost/peergroup/index.php (without a / at the end).
This is causing relative URLs to be computed differently.
A workaround is to use URLs that are relative to the site root (i.e. starting with a /).

syntax error, unexpected end of file when using include_once('header.php') [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
i just installed php 5.6.8 and my older scripts are considered as wrong, getting syntax error, unexpected end of file. On older PHP (5.2-5.3) it worked well, but now I don't know how to fix it to keep the functionality.
The basic problem is that in pages (like index.php) I use:
include_once("header.php");
include_once("some-page.php");
include_once("footer.php");
In header.php I have things like logo etc that appears on evey page so it goes like:
<html> all-the-standard-things-here <body> <div class="div_menu">
<ul id="menulist_root" class="mainlevel"><li id="menuitem_1">...</li></ul>
</div>
<div class="div_body">
<div class="div_center" >
<div id="page">
then goes standard page, html code etc and i finish with footer.php closing the divs:
</div> // end of page
</div> // end of div_center
</div> // end of div_body
etc
But the server doesn't like the end of header.php showing:
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\project\header.php on line 52 (which is the last line).
What to do?
Well, as it was working without any change on 5.3 ... it is a lot of code, but Ok, here it is. thanx for help.
<?php
include_once('default_functions.php');
if (!$security_check || $security_check <= $_SESSION['user']['level']) {
//ok
} else {
header("Location:users.php?action=loginAdmin");
die;
}
?>
<!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" xml:lang="sk" lang="sk">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Slovenské firemné hry Zima | Elcop</title>
<!--
<link href="http://www.elcop.sk/templates/elcop/favicon.ico" rel="shortcut icon" type="image/x-icon" />
-->
<!--[if IE]>
<link rel="stylesheet" href="/templates/elcop/css/ie.css" type="text/css" />
<![endif]-->
<!--[if IE 6]>
<link rel="stylesheet" href="/templates/elcop/css/ie6.css" type="text/css" />
<![endif]-->
<link href="default.css" rel="stylesheet" type="text/css">
<?php
if($_SERVER['HTTP_HOST'] != 'localhost'){
?>
<base href="" />
<meta name="description" content="Individuálne kreatívne riešenia pre komunikačné potreby našich klientov predovšetkým prostredníctvom event marketingu a špeciálnych PR projektov."/>
<meta name="keywords" content="elcop, korporatne bubnovanie, slovenske firemne hry, plazove inspiracie, teambuilding"/>
<meta name="robots" content="index, follow" />
<meta name="author" content="2create" />
<meta name="title" content="Slovenské firemné hry Zima | Elcop" />
<link href="http://www.elcop.sk/templates/elcop/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link rel="stylesheet" href="http://www.elcop.sk/components/com_rsform/front.css" type="text/css" media="screen" />
<link rel="stylesheet" href="http://www.elcop.sk/modules/mod_briaskISS/mod_briaskISS.css" type="text/css" />
<script type="text/javascript" src="http://www.elcop.sk/media/system/js/caption.js"></script>
<script type="text/javascript" src="http://www.elcop.sk/modules/mod_xyo_swf/lib/swfobject.js"></script>
<script type="text/javascript" src="http://www.elcop.sk/modules/mod_briaskISS/mod_briaskISS.js"></script>
<meta name="author" content="2create" />
<link rel="stylesheet" href="http://www.elcop.sk/templates/elcop/css/template.css" type="text/css" />
<link rel="stylesheet" href="http://www.elcop.sk/templates/elcop/css/menus.css" type="text/css" />
<link rel="stylesheet" href="http://www.elcop.sk/templates/elcop/css/content.css" type="text/css" />
<!--[if IE]>
<link rel="stylesheet" href="/templates/elcop/css/ie.css" type="text/css" />
<![endif]-->
<!--[if IE 6]>
<link rel="stylesheet" href="/templates/elcop/css/ie6.css" type="text/css" />
<![endif]-->
<script type="text/javascript" src="http://www.elcop.sk/templates/elcop/js/sfhover.js"></script>
<?php} else {?>
<link rel="stylesheet" href="template.css" type="text/css" />
<link rel="stylesheet" href="content.css" type="text/css" />
<?php}?>
<?php if(strlen($onload_css)) { echo $onload_css; }
if(strlen($onload_script)) { echo $onload_script; }
?>
</head>
<body <?php if(strlen($onload_event)) { echo $onload_event; }?>>
<?php
if($_SERVER['HTTP_HOST'] == 'localhost' && $_SESSION['user']['level'] >= 3) {
echo '<span style="color:red;margin:10px;">Work local (' . DB_NAME . ') !</span>';
} elseif($_SERVER['HTTP_HOST'] != 'localhost' && $_SESSION['user']['level'] >= 3) {
echo '<span style="color:green;margin:10px;">Work online!</span>';
} else {
}?>
<div class="div_main_container">
<?php
if($_SERVER['HTTP_HOST'] != 'localhost'){
?>
<div class="div_head">
<div class="div_topbox">
<div class="div_topmenu">
<ul class="menu"><li class="item14"><span>Home</span></li><li class="item15"><span>Mapa stránky</span></li><li class="item16"><span>Verzia pre tlač</span></li></ul>
</div>
<div class="div_languagemenu">
</div>
</div>
<br style="clear:both" />
<div class="div_slideshow">
<div class="div_float_logolink">
</div>
<noscript>
<div>ImageSlideShow requires Javascript</div>
</noscript>
<ul id="briask-iss35" class="briask-iss" style="width:736px;height:152px"><li><img src="http://www.elcop.sk/images/stories/Headers_2/img1.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img4.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img11.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img9.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img7.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img8.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img6.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img2.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img10.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img3.jpg" alt="Elcop" /></li><li><img src="http://www.elcop.sk/images/stories/Headers_2/img5.jpg" alt="Elcop" /></li></ul>
<script type="text/javascript">
var briaskPics35 = [0];
var briaskInstance35 =
new briaskISS(35,1,2000,80, briaskPics35);
</script>
</div>
</div>
<div class="div_menu">
<ul id="menulist_root" class="mainlevel"><li id="menuitem_1">O nás</li><li id="menuitem_2">Slovenské firemné hry<ul id="menulist_2"><li id="menuitem_2_1">SFH Zima</li><li id="menuitem_2_2">SFH Leto</li><li id="menuitem_2_3">SFH Pláže</li><li id="menuitem_2_4">Charitatívna iniciatíva</li></ul></li><li id="menuitem_3">Bedminton<ul id="menulist_3"><li id="menuitem_3_1">Účastnícky poplatok</li><li id="menuitem_3_2">Pravidlá a herný systém</li><li id="menuitem_3_3">Nominácia a nasadenie</li><li id="menuitem_3_4">Bonusové turnaje</li><li id="menuitem_3_5">Hodnotenie</li><li id="menuitem_3_6">Miesto a termíny</li><li id="menuitem_3_7">Najčastejšie otázky a odpovede</li><li id="menuitem_3_8">Prihlásené spoločnosti</li><li id="menuitem_3_9">Fotogaléria</li><li id="menuitem_3_10">Výsledky</li><li id="menuitem_3_11">Zaregistrujte sa!</li></ul></li><li id="menuitem_4">Golf</li><li id="menuitem_5">Korporátne bubnovanie</li><li id="menuitem_6">Eventy<ul id="menulist_6"><li id="menuitem_6_1">Event marketing</li><li id="menuitem_6_2">Ponuka eventov</li><li id="menuitem_6_3">Public Relations</li><li id="menuitem_6_4">Event manažment</li></ul></li><li id="menuitem_7">Referencie</li><li id="menuitem_8">Kontakt</li></ul>
</div>
<?php }?>
<div class="div_body">
<div class="div_center" >
<div id="page">

PHP SQL search with two parameters

Hey guys I am creating a search engine with two parameters, first is TEXT, second is RADIO BOX. However my query seems to know what the radio value is, but seems tends to ignore it completely. Can't quite put my finger on where I am going wrong. Any help would be greatly appreciated.
<?php
session_start();
?>
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8">
<title>site title</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- CSS
================================================== -->
<link rel="stylesheet" href="stylesheets/base.css">
<link rel="stylesheet" href="stylesheets/skeleton.css">
<link rel="stylesheet" href="stylesheets/layout.css">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
function search(partialSearch,level){
$.ajax({type: "POST",url:"php/bigsearch.php",data: {partialSearch: partialSearch, level: level},success:function(result){
$("#results").html(result);
}});#
alert("dsfsgdfg");
};
</script>
<!-- Favicons
================================================== -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
</head>
<body>
<!-- Primary Page Layout
================================================== -->
<!-- Delete everything in this .container and get started on your own site! -->
<div class="container">
<?php include 'navigation.php' ?>
<div class="sixteen columns">
<img src="images/glass.jpg" alt=""/>
<h3 class="forum">Search the site</h3>
<form action="bigsearch.php" method="POST" >
<label><input type="radio" name="level" value="beginner">Beginner</label>
<label><input type="radio" name="level" value="intemediate">Intemediate</label>
<label><input type="radio" name="level" value="advanced">Advanced</label>
<label><input type="radio" name="level" value="idontcare" checked="checked">I Don't Care</label>
<input type="text" name="partialSearch"/>
<input type="submit" name="search"/>
</form>
<div id="results">
<?php
include 'php/config.php';
$partialSearch = "%".$_POST['partialSearch']."%";
$check = $_POST['level'];
if($check == "idontcare"){
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE Keywords LIKE ? OR Name LIKE ? ");
$stmt->bind_param('ss',$partialSearch,$partialSearch);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}else{
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE Keywords LIKE ? OR Name LIKE ? AND Level = ?");
$stmt->bind_param('sss',$partialSearch,$partialSearch,$check);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}
$length = strlen($partialSearch);
if($length < 3){
}else{
if($stmt->num_rows == 0){
echo "No results";
}else{
while($rows = $stmt->fetch()){
echo "".$Name."";
echo "<p>".$Level."</p>";
}}}
?>
</div>
</div>
</div>
</div><!-- container -->
<!-- End Document
================================================== -->
</body>
</html>
<!-- Delete everything in this .container and get started on your own site! -->
<div class="container">
<?php include 'navigation.php' ?>
<div class="sixteen columns">
<img src="images/glass.jpg" alt=""/>
<h3 class="forum">Search the site</h3>
<form action="bigsearch.php" method="POST" >
<label><input type="radio" name="level" value="beginner">Beginner</label>
<label><input type="radio" name="level" value="intemediate">Intemediate</label>
<label><input type="radio" name="level" value="advanced">Advanced</label>
<label><input type="radio" name="level" value="idontcare" checked="checked">I Don't Care</label>
<input type="text" name="partialSearch"/>
<input type="submit" name="search"/>
</form>
<div id="results">
<?php
include 'php/config.php';
$partialSearch = "%".$_POST['partialSearch']."%";
$check = $_POST['level'];
if($check == "idontcare"){
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE Keywords LIKE ? OR Name LIKE ? ");
$stmt->bind_param('ss',$partialSearch,$partialSearch);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}else{
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE (Keywords LIKE ? OR Name LIKE ?) AND Level = ?");
$stmt->bind_param('sss',$partialSearch,$partialSearch,$check);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}
$length = strlen($partialSearch);
if($length < 3){
}else{
if($stmt->num_rows == 0){
echo "No results";
}else{
while($rows = $stmt->fetch()){
echo "".$Name."";
echo "<p>".$Level."</p>";
}}}
?>
</div>
</div>
</div>
</div><!-- container -->
<!-- End Document
================================================== -->
</body>
</html>
Try out this i guess the main problem with your sql command as you have mixed OR/AND in Where clause you should combine the OR between () to fix it
Hope this answer helps you

Categories