Php does not display codes below header - php

We set up our website and it displays fine in localhost but displays
this
when it's uploaded online. There are no errors in the console and the files are arranged fine. Honestly, I don't know where the problem is, I just assumed its within the code since everything else below include 'templates/header.php' is not displayed.
Here is a sample of my code for index.php
<?php
session_start();
include 'templates/header.php';
include 'library/announcements.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Resources for the Blind, Inc. Website 2017">
<meta name="author" content="Platinum Phenomena">
<title>Resources for the Blind, Inc.</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/animate.css">
<link rel="stylesheet" type="text/css" href="css/responsive.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script src="script.js"></script>
<!-- Google CDN jQuery with fallback to local -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"
</script>
<script>window.jQuery || document.write('<script src="js/minified/jquery-1.11.0.min.js"><\/script>')
</script>
try{
if( !file_exists("library/announcements.php") )
{ throw new Exception("Unable to include resources announcements"); }
else{ require_once("library/announcements.php"); }
}catch(Exception $e){
echo $e->getMessage();
exit;
}
?>
<header id="header" role="banner">
<div class="main-nav">
<div class="container">
<div class="header-top">
<div class="pull-right social-icons">
<img src="images/fb.png">
<img style="width:40px; height:40px;" src="images/yt.png">
<img src="images/ig.png">
<img src="images/twitter.png">
</div>
</div>
<div class="row">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">
<img class="img-responsive" src="images/logo.jpg" height="8" alt="logo">
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="scroll active">
Home
</li>
<li class="scroll">
Activities
</li>
<li class="scroll">
About Us
</li>
<li class="scroll">
Partners
</li>
<li class="scroll">
Contact
</li>
</ul>
</div>
</div>
</div>
</div>
</header>

Please include files after the head section in your case and try like below given
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Resources for the Blind, Inc. Website 2017">
<meta name="author" content="Platinum Phenomena">
<title>Resources for the Blind, Inc.</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/animate.css">
<link rel="stylesheet" type="text/css" href="css/responsive.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script src="script.js"></script>
<!-- Google CDN jQuery with fallback to local -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"
</script>
<script>window.jQuery || document.write('<script src="js/minified/jquery-1.11.0.min.js"><\/script>')
</script>
</head>
<body>
<?php
try{
if( !file_exists("templates/header.php") )
{ throw new Exception("Unable to include resources header"); }
else{ require_once("templates/header.php"); }
}catch(Exception $e){
echo $e->getMessage();
exit;
}
try{
if( !file_exists("library/announcements.php") )
{ throw new Exception("Unable to include resources announcements"); }
else{ require_once("library/announcements.php"); }
}catch(Exception $e){
echo $e->getMessage();
exit;
}
?>
</body>
</html>

I found out that it was a problem with connecting to the database. I forgot to check the db configurations. If someone else encounters this problem, please let me know. Thank you so much to everyone who tried to help! Much appreciated.

Related

Making current active website page not reload in navbar

I'll start off with saying that I am brand new to PhP, but am trying to use it to set load my header from 1 file into all of my website pages. I have successfully accomplished this and with that have also been able to set a .active class to whichever page is currently active.
My question is, if there is anyway I can make the active page not reload when it is clicked in the navbar out of personal preference. I have so far accomplished this by just setting the href link to "#" but I can't really do that if I am loading the same header from every file. Is there some way else I can do this possibly with PhP in my header.php file? Please let me know, be kind, again I'm brand new, here is my code...
INDEX.PHP
<html>
<head>
<!-- Meta & Other -->
<title>Infamous | Home</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Infamous official website">
<meta name="keywords" content ="Infamous, Minecraft, Server, Game, Gaming">
<meta name="author" content="MrWardy">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="Stylesheets/header.css">
<!-- Fonts -->
<script src="https://kit.fontawesome.com/35fad75205.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Kanit&display=swap" rel="stylesheet">
</head>
<body>
<?php $page = 'home'; include('header.php'); ?>
<!-- JavsScript -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>
</html>
APPLY.PHP
<html>
<head>
<!-- Meta & Other -->
<title>Infamous | Apply</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Infamous official website">
<meta name="keywords" content ="Infamous, Minecraft, Server, Game, Gaming, Apply, Application, Staff">
<meta name="author" content="MrWardy">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="Stylesheets/default.css">
<link rel="stylesheet" href="Stylesheets/header.css">
<!-- Fonts -->
<script src="https://kit.fontawesome.com/35fad75205.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Kanit&display=swap" rel="stylesheet">
</head>
<body>
<?php $page = 'apply'; include('header.php'); ?>
<!-- JavsScript -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>
</html>
HEADER.PHP
<nav id="header-nav" class="navbar-nav">
<div class="container grid-container">
<a class="<?php echo ($page == 'home') ? "active" : ""; ?> navlink" href="#"><i class="fas fa-home"></i> Home</a>
<a class="navlink" href="#rules"><i class="fas fa-book"></i> Rules</a>
<a class="<?php echo ($page == 'apply') ? "active" : ""; ?> navlink" href="./apply.php"><i class="fas fa-user"></i> Apply</a>
<a class="navlink" href="#store"><i class="fas fa-tags"></i> Store</a>
<a class="navlink" href="https://discord.gg/ZnN3f4P" target="_blank"><i class="fab fa-discord"></i> Discord</a>
<a class="navlink" href="https://www.youtube.com/channel/UCFvs3IZNgziCe0WARpJpYVw" target="_blank"><i class="fab fa-youtube"></i> YouTube</a>
</div>
</nav>
<img class="heading-banner mx-auto d-block" src="./Images/banner.png" alt="Infamous banner">
</header>
This way you can add many pages you want by using
array('page'=>'IDENTIFIER','title'=>'TITLE','link'=>'link','icon'=>'icon') separated by comma.
Header.php
<nav id="header-nav" class="navbar-nav">
<div class="container grid-container">
<?php
$pages=array(
array('page'=>'home','title'=>'Home','link'=>'./home.php','icon'=>'fas fa-home'),
array('page'=>'apply','title'=>'Apply','link'=>'./apply.php','icon'=>'fa-user'),
array('page'=>'other','title'=>'Other page','link'=>'./other_page.php','icon'=>'fa-user'),
array('page'=>'youtube','title'=>'Watch video','link'=>'https://www.youtube.com/channel/UCFvs3IZNgziCe0WARpJpYVw','icon'=>'fab fa-youtube','newtarget'=>1)
);
foreach($pages as $pg){
echo $pg['page']==$page?
'<a class="navlink active"><i class="'.$pg['icon'].'"></i> '.$pg['title'].'</a>':
'<a class="navlink" href="'.$pg['link'].'" '(.isset($pg['newtarget'])?' target="_blank"':'').'><i class="'.$pg['icon'].'"></i> '.$pg['title'].'</a>';
}
?>
</div>
</nav>
<img class="heading-banner mx-auto d-block" src="./Images/banner.png" alt="Infamous banner" />
</header>
If you want you can add a cursor style to navlink class, this way, even without a href your will have a nice cursor.

Calling a function from another PHP page [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I've been working on an e-commerce app and I took out all the HTML in my index page and created a function called component() like this:
function component($productName,$productPrice,$productImage){
$element = "
<div class=\"col-md-3 col-sm-6 my-3 my-md-0\">
<form action=\"index.php\" method=\"POST\">
<div class=\"card shadow\">
<div>
<img src=\"$productImage\" alt=\"image1\" class=\"img-fluid card-img-top\">
</div>
<div class=\"card-body\">
<h5 class=\"card-title text-sm-center\">$productName</h5>
<h6 class=\"text-sm-center\">
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"far fa-star\"></i>
</h6>
<p class=\"card-text text-sm-center\">
Some Quick example text to build on the card
</p>
<h5 class=\"text-sm-center\">
<small><s class=\"text-secondary\">$519</s></small>
<span class=\"price\">$productPrice</span>
</h5>
<button class=\"btn btn-warning\" type=\"submit\" name=\"add\">Add to Cart<i class=\"fas fa-shopping-cart\"></i></button>
</div>
</div>
</form>
</div>
";
echo $element;
}
?>
Now, im trying to access the HTML content of component in my index.php like this:
<?php require "component.php"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Shopping Cart</title>
<link rel="stylesheet" href="./dist/css/all.min.css">
<link rel="stylesheet" href="./dist/css/style.css">
<link rel="stylesheet" href="./dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css" integrity="sha256-46qynGAkLSFpVbEBog43gvNhfrOj+BmwXdxFgVK/Kvc=" crossorigin="anonymous" />
<!--<link rel="stylesheet" href="./dist/css/fa.5.11.2.css">-->
</head>
<body>
<div class="container">
<div class="row text-center py-5">
<?php
component(productName:"Product 1", productPrice:599, productImage:"./upload/product1.png" );
?>
</div>
</div>
<script src=".dist/js/jquery.min.js"></script>
<script src=".dist/js/popper.min.js"></script>
<script src=".dist/js/bootstrap.min.js"></script>
</body>
</html>
And I am getting this error:
Error Message : Parse error: syntax error, unexpected ':', expecting ',' or ')' in C:\xampp\htdocs\shopping\index.php on line 24
Please, I need help to proceed.
Thanks
Use below mentioned HTML.
<?php require "component.php"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Shopping Cart</title>
<link rel="stylesheet" href="./dist/css/all.min.css">
<link rel="stylesheet" href="./dist/css/style.css">
<link rel="stylesheet" href="./dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css" integrity="sha256-46qynGAkLSFpVbEBog43gvNhfrOj+BmwXdxFgVK/Kvc=" crossorigin="anonymous" />
<!--<link rel="stylesheet" href="./dist/css/fa.5.11.2.css">-->
</head>
<body>
<div class="container">
<div class="row text-center py-5">
<?php
component("Product 1", 599,"./upload/product1.png" );
?>
</div>
</div>
<script src=".dist/js/jquery.min.js"></script>
<script src=".dist/js/popper.min.js"></script>
<script src=".dist/js/bootstrap.min.js"></script>
</body>
</html>
You need to change just below mentioned calling function.
component("Product 1", 599,"./upload/product1.png" );

How can i stop this simple php calendar from caching the old dates?

I made this simple calender for a few friends to fill in all their dates, It all works fine when you update the dates but then when you go back to the calendar it shows all the old dates selected. You have to manually refresh the page to get the updated dates it's really frustrating.
You can demo it here: http://olli460.com/poker/index.php
If you click "Add/Edit Dates" then click on "oliver" and select a few random dates. When you go back to the calendar it's still showing all the old dates until you press F5.
This is my index.php
<?php
date_default_timezone_set('Europe/London');
//error_reporting(E_ALL);
$pageWeb = $_REQUEST['page'];
$pageWeb = filter_var($pageWeb, FILTER_SANITIZE_STRING);
if(empty($pageWeb)) {
$pageWeb = "main";
}
$mysqli = mysqli_connect("localhost","xxxxx","xxxxxx","xxxxxx") or die("Error " . mysqli_error($link));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Poker Calendar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.0.47/jquery.fancybox.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.0.47/jquery.fancybox.min.js"></script>
<link rel="shortcut icon" sizes="192x192" href="if_icon-82_667352.png">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!--<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">-->
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Arvo:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="theme.css">
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
</head>
<body>
<script src="https://use.fontawesome.com/8a36931ffe.js"></script>
<div class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
Poker Calendar
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<ul class="nav navbar-nav">
<li <?php if(empty($pageWeb)) { echo "class=\"active\""; } ?>><i class="fa fa-calendar" aria-hidden="true"></i> Calendar</li>
<li <?php if(empty($pageWeb) OR $pageWeb == "add-dates") { echo "class=\"active\""; } ?>><i class="fa fa-calendar-plus-o" aria-hidden="true"></i> Add/Edit Dates</li>
<li <?php if(empty($pageWeb) OR $pageWeb == "add-player") { echo "class=\"active\""; } ?>><i class="fa fa-user-plus" aria-hidden="true"></i> Add Player</li>
</div>
</div>
</div>
<div class="clearfix"></div>
<br /><br /><br /><br />
<div class="container-fluid">
<!-- START ALL CONTENT HERE -->
<?php
if(isSet($pageWeb)){
if (!(strpos($pageWeb, "http") === false)){
echo "not allowed";
}else{
include("$pageWeb.php");
}
} else {
include("main.php");
}
?>
<!-- END ALL CONTENT HERE -->
</div>
</body>
</html>
After they enter the dates i'm using this to redirect back to the main page, is this the issue?
<script>
$(document).ready(function () {
// Handler for .ready() called.
window.setTimeout(function () {
location.href = "index.php";
}, 3000);
});
</script>
if you want to fix that script, tell the browser not to cache the page:
<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
and why load data from mySQL? maybe use the Google Client Library (GitHub) instead?

Display products from database in php

I want to display product details in php page that is stored in mysql database.
my php page is as follows:
<?phpinclude 'databaseconfile.php';
$sql = "select * from book";
$result = mysql_query($sql);
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Shop | ShareMyBook</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/prettyPhoto.css" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link href="css/responsive.css" rel="stylesheet">
<link rel="shortcut icon" href="images/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch- icon-57-precomposed.png">
</head>
<body>
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<?phpwhile ($row = mysql_fetch_array($result))
{?>
<img src="images/home/" alt="" />
<h2><?php echo $row['Book_Name']; ?></h2>
<p>Book 10</p>
<?php}?>
</div>
<div class="product-overlay">
<div class="overlay-content">
<h2>Price</h2>
<p>Book 10</p>
<i class="glyphicon glyphicon-eye-open"></i>view Book
</div>
</div>
</div>
<div class="choose">
<ul class="nav nav-pills nav-justified">
<li><i class="fa fa-plus-square"></i>Add to wishlist</li>
<li><i class="fa fa-shopping-cart"></i>Add to cart</li>
</ul>
</div>
</div>
</div>
</body>
</html>
when I try to run this page it says-Notice:Undefined variable:row on line 32, when it is already defined.
The mistake is the space required between php and while loop. I already told you in comment. Replace this chunk of code:
Replace first line with:
<?php include 'databaseconfile.php';
and :
<div class="productinfo text-center">
<?php while ($row = mysql_fetch_array($result))
{?>
<img src="images/home/" alt="" />
<h2><?php echo $row['Book_Name']; ?></h2>
<p>Book 10</p>
<?php}?>
</div>
The mistake is in first line.<?phpinclude 'databaseconfile.php';
You have to give space between php tag and include like this <?php include 'databaseconfile.php';

php while loop for dynamic post variables

previous page (added as edit)
<!DOCTYPE html>
<html lang="en">
<head>
<script src="jquery-2.1.1.min.js"></script>
<script src="jquery/jquery-ui-1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui-1.11.2/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.1-dist/dist/css/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.1-dist/dist/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.1-dist/dist/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.1-dist/dist/css/bootstrap.min.css">
<script src="bootstrap-3.3.1-dist/dist/js/bootstrap.js"></script>
<script src="bootstrap-3.3.1-dist/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="/CSS/handover.css">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>IgG Dashboard</title>
<script>
$(document).ready(function() {
// Datepicker Popups calender to Choose date.
$(function() {
$("#datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
});
});
</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="../../assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js 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]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Dashboard.php">IgG Dashboard</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Messages</li>
<li>Scripts and Options Editor</li>
<li>Add User</li>
<li id= "dash"><p >Welcome <?php echo " " .$_SESSION['myuser']." ";?><a class="btn bg-info" href="Dashboard.php">Main Site</a></p></li>
</ul>
</div><!-- /.nav-collapse -->
</div><!-- /.container -->
</div><!-- /.navbar -->
<div class="jumbotron">
<div class="container-fluid">
<br>
<br>
<br><br>
<?php
$scripte = ($_POST["scriptake"]);
$scriptot =($_POST["scriptot"]);
include 'config.php';
echo '<h2>'.$scripte.' Equipment</h2>';
echo '<h2>Total Hours '.$scriptot.'</h2>';
echo'<table class="table table-responsive"><tr><form action="equiptest.php" method="post"><th>Script Hour</th><th>Equipment Required</th><th>Stage</th></tr>';
$x = 1;
$p = 1;
$r=1;
while($x <= $scriptot ) {
echo "<tr><td>".$x++."</td><td><input name='equip".$r++."'` ></td><td><input name='stage".$p++."'><input name='ohyeah' type='hidden' value= '".$scriptot."'></td></tr>";
}
echo'<tr><td colspan="2"><input type="submit" class="btn btn-primary"></td></tr></form></table>';
?>
</div>
Can I do this with a post variable. I get undefined. However if I write
equip1 = ($_POST["equip1"]);
echo $equip1;
it works
<?php
$scriptot = ($_POST["ohyeah"]);// working
$y = 1;
$x = 1;
$r= 1;
while($x <= $scriptot ) {//working
${"equip".$x} = ($_POST["equip".$x]); //not working
echo ${"equip" .$x};//not working
$x++; // working
}
I am trying to create dyanmic variables. Idea in this case is to insert POST to database
so want
$equip1
$equip2
$equip3 etc
Thanks
For organizational purposes, you should really use arrays.
For instance, in a form you can set the input name to 'equip[1]' and the value will imported to PHP as $_POST['equip'][1]. Then you can just run:
foreach($_POST['equip'] as $key=>$value) {
# where $key = 1, the $value will be of equip[1]
}
May not be exactly what you're after, but it seems like a much cleaner solution than what you are attempting.
This is how I try.
<?php while ( have_posts() ) : the_post(); ?>
<div class="contentTitle"><?php the_title(); ?></div>
<div class="contentText">
<?php the_content(); ?>
</div>
<?php endwhile ?>

Categories