PHP SQL search with two parameters - php

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

Related

PHP website form to database doesn't work

I've currently made an php form on my website that sends the information to my database, but when someone uses it it only posts two of the 4 input fields to the database, see the image i linked below.
It's an refund site by the way written in Norwegian so, please use Google Translate if needed :D
Here's my refund.php:
<html>
<head>
<link type="text/css" media="all" href="https://bootswatch.com/4/lumen/bootstrap.min.css" rel="stylesheet" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta charset="utf-8" />
<title>NattLAN</title>
<meta name="author" content="ukieweb" />
<meta name="keywords" content="soon, css3, template, html5 template" />
<meta name="description" content="Balk - Page Template" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<!-- Favicons -->
<link rel="apple-touch-icon" sizes="144x144" href="assets/img/favicons/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="114x114" href="assets/img/favicons/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="72x72" href="assets/img/favicons/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" href="assets/img/favicons/apple-touch-icon.png" />
<link rel="shortcut icon" href="assets/img/favicons/favicon.png" />
<!-- Google Fonts -->
<link href='http://fonts.googleapis.com/css?family=Exo+2:400,100,100italic,200,200italic,300,300italic,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic' rel='stylesheet' type='text/css'>
<style>
body {
background-color: #F0F0F0;
}
</style>
</head>
<body>
<!DOCTYPE html>
<p align="center"><img src="http://24.media.tumblr.com/0128a30614276768bf956ad868604b5d/tumblr_n6zhprHRGv1qgefibo1_400.gif"></p>
<p> </p>
<h3 align="center" color="black"> Refunderingsskjema</h3>
<form action="send.php" method="post">
<p align="center">Navn på deltaker:<br></p>
<p align="center"><input type="text" name="u_deltaker" required><br></p>
<p align="center">Navn på betaler:<br></p>
<p align="center"><input type="text" name="u_payer" required><br></p>
<p align="center">Telefonnummer:<br></p>
<p align="center"><input type="text" name="u_phone" required><br></p>
<p align="center">Kontonummer:<br></p>
<p align="center"><input type="text" name="u_konto" required><br></p>
<p align="center"><input class="btn btn-success" type="submit" value="Send"><br></p>
</form>
<p align="center">Hjelp! Hva betyr alt dette ovenfor? KLIKK HER!</p>
</body>
</html>
<footer id="footer">
<div class="container">
<!-- footer socials -->
<div class="row">
<div class="footer_socials col-sm-12 text-center">
<div class="contact_icons">
<ul class="contact_socials clearfix">
<!-- social icons -->
</ul>
</div>
<img src="oldwebsite/assets/nb.png" width="162" height="53" class="navbar-logo-img" alt="">
<div class="copyright">Kontakt: kontakt#nattlan.net</div>
<div class="copyright">© Copyright 2017 NattLAN</div>
Here's my send.php:
<title>NattLAN - Refund</title>
<?php
require 'connection.php';
$conn = Connect();
$deltaker = $conn->real_escape_string($_POST['u_deltaker']);
$payer = $conn->real_escape_string($_POST['u_payer']);
$phone = $conn->real_escape_string($_POST['u_phone']);
$konto = $conn->real_escape_string($_POST['u_konto']);
$query = "INSERT into tb_cform (u_deltaker,u_payer,u_phone,u_konto) VALUES('" . $deltaker . "','" . $payer . "','" . $phone . "','" . $konto . "')";
$success = $conn->query($query);
if (!$success) {
die("Fail".$conn->error);
}
echo "Success";
$conn->close();
?>
Here's my connection.php:
<?php
function Connect()
{
$dbhost = "PRIVATE";
$dbuser = "PRIVATE";
$dbpass = "PRIVATE";
$dbname = "PRIVATE";
// Create connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
return $conn;
}
?>
My database only put's the two last information from the form in the database, image showing the problem:
Image form DB showing that it inputs 0's in two of the fields:
https://prntscr.com/had0ak
Can someone help me figure out why this happens?
Thanks :D
I think it's inserting 0 because the column type is int? Check on that and change to varchar.

I need simple code to make the entire webpage responsive (PHP code)

I have coded a working page but did not incorporate webpage responsiveness which I now need desperately! Is there a single line of code that will make the entire webpage responsive or do I need to make each element responsive?
I have tried to include the following code but to no success:
<meta name="viewport" content="width=device-width, initial-scale=1">
Here is the full code:
<?php
session_start();
$customer = $_SESSION['id_login'];
$order = $_SESSION['id_login'];
if (!isset($_SESSION['mysesi']) && !isset($_SESSION['mytype'])=='customer')
{
echo "<script>window.location.assign('LoginAndReg.php')</script>";
}
?>
<?php
include("admin/php/myFunctions.php");
#mysql_connect("localhost","root","") or die("Could not connect to database");
#mysql_select_db("bookstore") or die("Could not select database");
$displayImages = "";
if((isset($_GET['cat']) ? $_GET['cat'] : '') == "children")
$sqlSelProd = #mysql_query("select * from tblproduct where prod_cat = '$_GET[cat]'") or die(mysql_error());
else if((isset($_GET['cat']) ? $_GET['cat'] : '') == "Horror")
$sqlSelProd = #mysql_query("select * from tblproduct where prod_cat = '$_GET[cat]'") or die(mysql_error());
else if((isset($_GET['cat']) ? $_GET['cat'] : '') == "Thriller")
$sqlSelProd = #mysql_query("select * from tblproduct where prod_cat = '$_GET[cat]'") or die(mysql_error());
else
$sqlSelProd = #mysql_query("select * from tblproduct") or die(mysql_error());
if(mysql_num_rows($sqlSelProd) >= 1){
while($getProdInfo = mysql_fetch_array($sqlSelProd)){
$prodNo = $getProdInfo["prod_no"];
$prodID = $getProdInfo["prod_id"];
$prodName = $getProdInfo["prod_name"];
$prodPrice = $getProdInfo["prod_price"];
$displayImages .= '<div class="col col_14 product_gallery">
<img src="images/product/'.$prodNo.'.jpg" alt="Product '.$prodNo.'" width="170" height="150" />
<h3>'.$prodName.'</h3>
<p class="product_price">R '.$prodPrice.'</p>
Add to Cart</div>';
}
}
?>
<!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>
<!-- Responsive code -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Great selling Book Store</title>
<link href="css/slider.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
</head>
<body id="home">
<div id="main_wrapper">
<div id="main_header">
<div id="site_title"><h1>Book Store</h1></div>
<div id="header_right">
<div id="main_search">
<form action="products.php" method="get" name="search_form">
<input type="text" value="Search" name="keyword" onfocus="clearText(this)" onblur="clearText(this)" class="txt_field" />
<input type="submit" name="Search" value="" alt="Search" id="searchbutton" title="Search" class="sub_btn" />
<p>Welcome, <?php echo $_SESSION['mysesi'] ?></p> Log Out
<?php echo $customer ?>
<?php echo $order ?>
</form>
</div>
</div> <!-- END -->
</div> <!-- END of header -->
<div id="main_menu" class="ddsmoothmenu">
<ul>
<li>Home</li>
<li>Books</li>
<li>Cart</li>
<li>Checkout</li>
<li>About</li>
</ul>
<br style="clear: left" />
</div> <!-- end of menu -->
<div id="main_middle">
<img src="images/image_book.png" alt="Image 01" width="500" height="170" />
<h1>Great Selling book Store</h1>
<p>Great Selling book Store is a country wide book store.</p>
Browse All books
</div> <!-- END of middle -->
<div id="main_top"></div>
<div id="main">
<div id="sidebar">
<h3>Categories</h3>
<ul class="sidebar_menu">
<li>Children</li>
<li>Horror</li>
<li>Thriller</li>
</ul>
</div> <!-- END of sidebar -->
<div id="content">
<h2>Products</h2>
<?php echo $displayImages; ?>
</div> <!-- END of content -->
<div class="cleaner"></div>
</div> <!-- END of main -->
<div id="main_footer">
<div class="cleaner h40"></div>
<center>
Copyright © 2048 DigitalNinja
</center>
</div> <!-- END of footer -->
</div>
<script type='text/javascript' src='js/logging.js'></script>
</body>
</html>
I would recommend using bootstrap it's easy to use and it can make your page responsive by just adding some classes to your file.
I think this is what you've been looking for:
How to get just the responsive grid from Bootstrap 3?

Log users ip on login PHP mysql

I want to log the users IP when they login all I want it to do it update a column
I know $_SERVER['REMOTE_ADDR']; get their ip.
I want to log it on login on their username row in mysql.
Here's an image of my mysql table
https://gyazo.com/cf5b223df03d0da8a15bf61ed037d847
LoginCheck.php:
<?php
# Processes
function cleanString($con, $string) {
return mysqli_real_escape_string($con, stripcslashes($string));
}
# buttons use the request method
if (isset($_REQUEST['login'])) {
$username = strtolower(cleanString($con, $_POST['username']));
$password = cleanString($con, $_POST['password']);
$errors = array();
if (empty($username) || empty($password)) {
# If they left the shit blank like a jew
$errors[] = "Please make sure you entered a valid username and password";
}
$password = md5($password);
$db_check_username = mysqli_query($con, "SELECT username FROM users WHERE username='$username' OR email='$username'");
$db_check_userdata = mysqli_query($con, "SELECT username,password FROM users WHERE username='$username' AND password='$password' OR email='$username' AND password='$password'");
if (!$db_check_username || !$db_check_userdata) {
$errors[] = mysqli_error($con);
}
if (mysqli_num_rows($db_check_username) == 0) {
# If the username doesn't exist like a bitch
$errors[] = "No account could be found with that username.";
}
if (mysqli_num_rows($db_check_userdata) == 0) {
# If the Username and Password don't match
$errors[] = "Username and Password combination incorrect.";
}
if(empty($errors)) {
session_start();
$_SESSION['username'] = $username;
$success[] = "You have successfully logged in. Redirecting in a moment.";
echo '<meta http-equiv="refresh" content="5; url=index.php" />';
} else {
$danger = $errors;
}
}
?>
Login.php
<?php
# Include da files mate
include('includes/config.php');
include('includes/logincheck.php');
# Other Shit
//nothing yet
?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<meta charset="utf-8" />
<title>Twisted Movies | Login Page</title>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
<meta content="" name="description" />
<meta content="" name="author" />
<!-- ================== BEGIN BASE CSS STYLE ================== -->
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
<link href="assets/plugins/jquery-ui/themes/base/minified/jquery-ui.min.css" rel="stylesheet" />
<link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
<link href="assets/css/animate.min.css" rel="stylesheet" />
<link href="assets/css/style.min.css" rel="stylesheet" />
<link href="assets/css/style-responsive.min.css" rel="stylesheet" />
<link href="assets/css/theme/red.css" rel="stylesheet" id="theme" />
<!-- ================== END BASE CSS STYLE ================== -->
<!-- ================== BEGIN BASE JS ================== -->
<script src="assets/plugins/pace/pace.min.js"></script>
<!-- ================== END BASE JS ================== -->
</head>
<body class="pace-top">
<!-- begin #page-loader -->
<div id="page-loader" class="fade in"><span class="spinner"></span></div>
<!-- end #page-loader -->
<div class="login-cover">
<div class="login-cover-image"><img src="assets/img/login-bg/bg-1.jpg" data-id="login-cover-image" alt="" /></div>
<div class="login-cover-bg"></div>
</div>
<!-- begin #page-container -->
<div id="page-container" class="fade">
<!-- begin login -->
<div class="login login-v2" data-pageload-addclass="animated fadeIn">
<!-- begin brand -->
<div class="login-header">
<div class="brand">
<span class="logo"></span> Twisted Movies
<small>Where the best movies are AD free!</small>
</div>
<div class="icon">
<i class="fa fa-sign-in"></i>
</div>
</div>
<!-- end brand -->
<div class="login-content">
<form action="" method="POST" class="margin-bottom-0">
<div class="text-center">
<?php
if (!empty($success)) {
foreach ($success as $value) {
echo '<div class="alert alert-success">';
echo $value.'<br>';
echo '</div>';
}
} elseif (!empty($danger)) {
foreach ($danger as $value) {
echo '<div class="alert alert-danger">';
echo $value.'<br>';
echo '</div>';
}
} elseif (!empty($warning)) {
foreach ($warning as $value) {
echo '<div class="alert alert-warning">';
echo $value.'<br>';
echo '</div>';
}
} elseif (!empty($info)) {
foreach ($info as $value) {
echo '<div class="alert alert-info">';
echo $value.'<br>';
echo '</div>';
}
} else {
echo '<div class="alert alert-info">';
echo "Please enter a username and password.";
echo '</div>';
}
?>
</div>
<div class="form-group m-b-20">
<input type="text" name="username" placeholder="Username" class="form-control input-lg"/>
</div>
<div class="form-group m-b-20">
<input type="password" name="password" placeholder="Password" class="form-control input-lg"/>
</div>
<div class="checkbox m-b-20">
<label>
<input type="checkbox" /> Remember Me
</label>
</div>
<div class="login-buttons">
<button type="submit" name="login" class="btn btn-success btn-block btn-lg">Sign me in</button>
</div>
<div class="m-t-20">
Not a member yet? Click here to register.
</div>
<center><?php include 'includes/footer.php'; ?></center>
</form>
</div>
</div>
<!-- end login -->
</div>
<!-- end page container -->
<!-- ================== BEGIN BASE JS ================== -->
<script src="assets/plugins/jquery/jquery-1.9.1.min.js"></script>
<script src="assets/plugins/jquery/jquery-migrate-1.1.0.min.js"></script>
<script src="assets/plugins/jquery-ui/ui/minified/jquery-ui.min.js"></script>
<script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="assets/crossbrowserjs/html5shiv.js"></script>
<script src="assets/crossbrowserjs/respond.min.js"></script>
<script src="assets/crossbrowserjs/excanvas.min.js"></script>
<![endif]-->
<script src="assets/plugins/jquery-hashchange/jquery.hashchange.min.js"></script>
<script src="assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="assets/plugins/jquery-cookie/jquery.cookie.js"></script>
<!-- ================== END BASE JS ================== -->
<!-- ================== BEGIN PAGE LEVEL JS ================== -->
<script src="assets/js/login-v2.demo.min.js"></script>
<script src="assets/js/apps.min.js"></script>
<!-- ================== END PAGE LEVEL JS ================== -->
<script>
$(document).ready(function() {
App.init(ajax=true);
LoginV2.init();
});
</script>
</body>
</html>
Right after you have session_start():
$ip = $_SERVER['REMOTE_ADDR'];;
$stmt = $con->prepare("UPDATE users SET `IP`=? WHERE username=?");
$stmt->bind_param("ss", $ip, $username);
$stmt->execute();
Some tips:
Try to always use prepared statements when dealing with user data.
use a HTTP class to get the IP. The IP is not always in REMOTE_ADDR, especially if the site is behind a proxy such as Cloudflare

Age Verify code kicking people out of to old?

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.

Not getting the reason for the error [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 8 years ago.
There are quite a few solutions available for this error but none seems to be working for me. I am a new php developer and trying to create web site using php programs.
The error I'm getting is "Warning: Cannot modify header information - headers already sent by (output started at /home/influss/public_html/Influsstest/hiremain.php:39) in /home/influss/public_html/Influsstest/hiremain.php on line 74"
I have checked the line no. 39 and do not find any whitespace before or after the php. also there are no white spaces in the beginning or the end of the program but still I'm getting this error.
the code is as follows:
`
<!doctype html>
<html><!-- InstanceBegin template="/Templates/registrtion.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Hire Main</title>
<!-- InstanceEndEditable -->
<link href="/css/styles-reg.css" rel="stylesheet" type="text/css" media="all">
<link href="/css/reg.css" rel="stylesheet" type="text/css" media="all"/>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,500' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Slabo+13px' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700' rel='stylesheet' type='text/css'>
<!-- InstanceBeginEditable name="head" -->
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all">
<!-- InstanceEndEditable -->
</head>
<body>
<div id="wrapper">
<div id="top">
<div id = "logo">
<img src="images/logo2.jpg">
</div>
<div id = "social-media">
<p>For additional information<br>Call Phone No.</p>
<ul>
<li><img src="/images/icons/facebook1.png"></li>
<li><img src="/images/icons/twitter1.png"></li>
<li><img src="/images/icons/linkedin1.png"></li>
<li><img src="/images/icons/googleplus1.png"></li>
</ul>
</div>
</div>
<!-- <div id="Banner">
</div>
--> <div id="Content-wrapper">
<div id="content">
<!-- InstanceBeginEditable name="content" -->
**<?php**
error_reporting(E_ALL); ini_set('display_errors', 'On');
function renderForm($id, $error)
{
?>
<?php
if ($error != '')
{
echo '<div style="margin:0 200px;padding:4px; color:red ;font-weight:bold;">'.$error.'</div>';
}
?>
<form action="hiremain.php" method="post" class="newreg">
<fieldset class="row1">
<p>
<label class="labelstyle">Enter Registration ID: *</label>
<input type="text" name="regid" value="<?php echo $id;?>"/>
</p>
</fieldset>
<p></p>
<input class="button1" type="submit" name="submit" value="Get Details">
</form>
<p></p>
<?php
}
?>
<?php
include('connect.php');
if (isset($_POST['submit']))
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header('location:hireedit.php?regid='.$id);
}
else
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header("location:hireedit.php?regid=" . $id);
}
Else
{
$error = "Please register first";
renderForm($id, $error);
}
}
mysql_free_result($result);
}
else
{
$error = "";
$id="";
renderform($id, $error);
}
?>
Register a Request
Home
<p></p>
<!-- InstanceEndEditable -->
</div>
</div>
<div id="footer">
<p>©Copyright 2014 • All rights Reserved • Influss.com, Chennai, Mob: +9112345-12345, E-mail: abc#influss.com</p>
</div>
</div>
</body>
<!-- InstanceEnd -->
</html>
`
The error happens to be in the line which is marked by *.
Request somebody help me out on this.
You can't send headers after an html output.
You have to put them before
<!doctype html>
You can resolve this using:
<?php
error_reporting(E_ALL); ini_set('display_errors', 'On');
function renderForm($id, $error)
{
if ($error != '')
{
$problems = '<div style="margin:0 200px;padding:4px; color:red ;font-weight:bold;">'.$error.'</div>';
}
}
include('connect.php');
if (isset($_POST['submit']))
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header('location:hireedit.php?regid='.$id);
}
else
{
$id = $_POST['regid'];
$sql = "Select * from hirefinal where hr_id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);
if ($total_results > 0)
{
header("location:hireedit.php?regid=" . $id);
}
Else
{
$error = "Please register first";
renderForm($id, $error);
}
}
mysql_free_result($result);
}
else
{
$error = "";
$id="";
renderform($id, $error);
}
?>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/registrtion.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Hire Main</title>
<!-- InstanceEndEditable -->
<link href="/css/styles-reg.css" rel="stylesheet" type="text/css" media="all">
<link href="/css/reg.css" rel="stylesheet" type="text/css" media="all"/>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,500' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Slabo+13px' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700' rel='stylesheet' type='text/css'>
<!-- InstanceBeginEditable name="head" -->
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all">
<!-- InstanceEndEditable -->
</head>
<body>
<div id="wrapper">
<div id="top">
<div id = "logo">
<img src="images/logo2.jpg">
</div>
<div id = "social-media">
<p>For additional information<br>Call Phone No.</p>
<ul>
<li><img src="/images/icons/facebook1.png"></li>
<li><img src="/images/icons/twitter1.png"></li>
<li><img src="/images/icons/linkedin1.png"></li>
<li><img src="/images/icons/googleplus1.png"></li>
</ul>
</div>
</div>
<!-- <div id="Banner">
</div>
--> <div id="Content-wrapper">
<div id="content">
<!-- InstanceBeginEditable name="content" -->
<?php
echo $problems;
?>
<form action="hiremain.php" method="post" class="newreg">
<fieldset class="row1">
<p>
<label class="labelstyle">Enter Registration ID: *</label>
<input type="text" name="regid" value="<?php echo $id;?>"/>
</p>
</fieldset>
<p></p>
<input class="button1" type="submit" name="submit" value="Get Details">
</form>
<p></p>
Register a Request
Home
<p></p>
<!-- InstanceEndEditable -->
</div>
</div>
<div id="footer">
<p>©Copyright 2014 • All rights Reserved • Influss.com, Chennai, Mob: +9112345-12345, E-mail: abc#influss.com</p>
</div>
</div>
</body>
<!-- InstanceEnd -->
</html>

Categories