I am trying to get echo $userRow['student_firstname']; to pass into the html so I can use it as a automatic way to change displaying the users first name & logout with register & login. The first echo $userRow['student_firstname']; does work, however the second does not. The idea would be able to get the second to work, so I can remove the first. If there isn't a session then it displays the login & register.
<?php
session_start();
include_once 'dbconnect_new.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimal-ui">
<link href="favicon.png" type="image/x-icon" rel="shortcut icon">
<link href="assets/css/master.css" rel="stylesheet">
<script src="assets/plugins/jquery/jquery-1.11.3.min.js"></script>
</head>
<?php if(isset($_SESSION['user'])) {
// error_reporting(E_ALL ^ E_DEPRECATED);
$res=mysql_query("SELECT * FROM studentdata WHERE student_id=".$_SESSION['user']);
if ($res === FALSE){
die(mysql_error());
}
while($userRow=mysql_fetch_array($res))
{
echo $userRow['student_firstname'];
}
?>
<li class="dropdown">
<a href="">
<?php echo $userRow['student_firstname'];?><span class="nav-subtitle">Account</span></a</li>
<li>Logout<span class="nav-subtitle">Goodbye</span></li>
<?php } else { ?>
<li>Register<span class="nav-subtitle">for Students</span></li>
<li>Login<span class="nav-subtitle">for Students</span></li>
<?php } ?>
</html>
Check this link out http://php.net/manual/en/function.mysql-fetch-array.php,
Tip: USE mysqli/pdo as mysql is deprecated.
<?php
session_start();
include_once 'dbconnect_new.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimal-ui">
<link href="favicon.png" type="image/x-icon" rel="shortcut icon">
<link href="assets/css/master.css" rel="stylesheet">
<script src="assets/plugins/jquery/jquery-1.11.3.min.js"></script>
</head>
<?php
if (isset($_SESSION['user'])) {
// error_reporting(E_ALL ^ E_DEPRECATED);
$res = mysql_query("SELECT * FROM studentdata WHERE student_id=" . $_SESSION['user']);
if ($res === FALSE) {//IF QUERY RETURNS NULL
die(mysql_error());
} else {
$userRow = mysql_fetch_array($res, MYSQL_ASSOC); //DATA IN ARRAY TYPE
//IF BELOW DOES NOT WORK USE print_r(); to check the structure of array !
?>
<li class="dropdown">
<?php echo $userRow['student_firstname']; //ACCESS DATA THROUGH ITS INDEX ?><span class="nav-subtitle">Account</span>
</li>
<li>
Logout<span class="nav-subtitle">Goodbye</span>
</li>
<?php
}
} else {
?>
<li>Register<span class = "nav-subtitle">for Students</span></li>
<li>Login<span class = "nav-subtitle">for Students</span></li>
<?php } ?>
</html>
I Hope this works !
Related
I am currently using a template file called single-product.php and want to check for page template in header.php. I've tried using get_page_template_slug($post->ID) but it returns empty. I've also tried is_page_template('single-product.php'); but that returns nothing, as well.
Here's my header. You'll notice that I'm trying to get the template file through s_page_template('single-product.php') ny setting it as the value of $isProductPodTemplate at the top and use it in the if statement at the bottom:
<?php
$page = get_the_title($post->ID);
$frontpageId = get_option('page_on_front');
$isStandardTemplate = is_page_template('standard.php');
$isContactTemplate = is_page_template('contact.php');
$isProductPodTemplate = is_page_template('single-product.php');
?>
<!DOCTYPE html>
<html id="mainHTML" lang="en">
<head>
<title>Architectural Iron Works</title>
<meta name="description" content="Architectural Iron Works">
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link rel=icon type="img/ico" href=/favicon.ico> -->
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(); ?>/main.bundle.css" />
<link href="https://fonts.googleapis.com/css?family=Poiret+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<?php wp_head(); ?>
<script type="text/javascript">
document.getElementById("mainHTML").style.display = "none";
</script>
</head>
<body>
<!-- Header -->
<?php
if ($post->ID == $frontpageId)
{
get_template_part('/includes/_home-header');
echo "<div class='main-content'>";
}
else if (is_404() ||
$isContactTemplate ||
$isStandardTemplate)
{
get_template_part('/includes/_no-banner-header');
echo "<div class='main-content no-banner'>";
}
else if ($isProductPodTemplate)
{
// do something
}
else
{
get_template_part('/includes/_default-header');
echo "<div class='main-content'>";
}
?>
How to make an page only accessible when logged in, in PHP?
I want you when you click on the background to defend two buttons with Login And Register and you can only access these two buttons after you log in.
<?php
session_start();
include_once 'dbconnect.php';
?>
<!DOCTYPE html>
<HTML>
<head>
<title>NCS pagina principala</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" >
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" >
</head>
<body>
<?php if (isset($_SESSION['usr_id'])) { ?>
<FONT size="4%" color="#66ffff" FACE="cursive">Esti conectat cu:</FONT><i><FONT size="5" color="#66ff66"> <?php echo $_SESSION['usr_name']; ?></FONT></i>
<link rel="stylesheet" href="styles/buttonstyle.css">
<a class="button" href="logout.php">Delogheaza-te</a>
<?php } else { ?>
<link rel="stylesheet" href="styles/buttonstyle.css">
<a class="button" href="login.php">Logheaza-te</a>
<a class="button" href="form.html">Cerere cont</a>
<?php } ?>
<head>
<a class="button" href="blacklist.php">BlackList</a>
<CENTER>
<BODY STYLE = "BACKGROUND: url(https://cdn.discordapp.com/attachments/389773843813629972/389781868247253002/thumb-1920-553248.jpg); BACKGROUND-SIZE:130%"></BODY>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
</HTML>
try this (after session_start(); ):
if (!isset($_SESSION['usr_id'])) header("Location:logout.php");
and logout.php must be
<?php
session_start();
session_destroy();
header("Location:login.php");
?>
then, in login.php you write your login code
This code work before this. after i format my laptop, i cant use this code anymore. please help me to solve this. this is my final year project. Fatal error: Cannot redeclare class data in D:\xampp\htdocs\Test1\tedboy\include\home\header.php on line 11
?php include('db.php'); ?>
<?php session_start(); ?>
<?php //print_r($_SESSION['cart']); ?>
<?php date_default_timezone_set('Asia/Kuala_Lumpur'); ?>
<?php
$jim = new data();
$countproduct = $jim->countproduct();
$cat = $jim->getcategory();
class data {
function countproduct(){
$count = 0;
$cart = isset($_SESSION['cart']) ? $_SESSION['cart']:array();
foreach($cart as $row):
if($row['qty']!=0){
$count = $count + 1;
}
endforeach;
return $count;
}
function getcategory(){
$result = mysql_query("SELECT * FROM category");
return $result;
}
}
?>
<!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="">
<meta name="author" content="">
<title>Tedboy Bakery</title>
<link rel="icon" href="images/home/Tedboy.png" type="image" />
<link href="css/bootstrap1.min.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/main1.css" rel="stylesheet">
<link href="css/responsive1.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head><!--/head-->
<body>
<header id="header"><!--header-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Tedboy Bakery</title>
<link rel="icon" href="images/home/damailers_logo.png" type="image" />
<link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<header>
<nav>
<ul id="nav">
<li>Home</li>
<li>Menu</li>
<li>Cart <span class="badge"></span></li>
<li>Gallery</li>
<li><a href="contact.php" >Contact</a></li>
<li>About Us</li>
</ul>
</nav>
</header>
<div class="wrapper">
<div class="border"></div>
</div>
</body>
</html>
</header><!--/header-->
that's because you are using the class before defining it!
Move the Definition of the data class before this line:
$jim = new data();
First, you should declare your data class before using it.
class data { ...
$jim = new data();
Then, double check that your included files don't have the data class declaration already.
I'm building a custom theme in Wordpress and I need to add a CSS attribute to the body tag when the URL ends in ?checklist-view=1
What is wrong with my code below, since no fullscreen is being added?
I understand that I need to use the superglobal $_GET, however I'm completely new to PHP.
Is there an easier way to do this with the body_class template tag (like im trying below) or is this something that would require more complicated PHP
EDIT: Changed $class to equal a string and not have it set to an array.
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0">
<title>Process Street <?php wp_title(); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<!--[if lt IE 9]>
<script src="<?php echo get_stylesheet_uri(); ?>bower_components/html5shiv/dist/html5shiv.js"></script>
<![endif]-->
<?php wp_head(); ?>
</head>
<?php
//?checklist-view=1
$is_checklist = $_GET['checklist-view'];
$class= 'fullscreen';
if($is_checklist == '1') {
echo $class;
}
?>
<body <?php body_class($class); ?>>
You shouldn't echo the class but, rather, you should just assign it to the variable to be passed to body_class() later. I'd also check whether or not checklist-view is set, to avoid errors:
<?php
$is_checklist = $_GET['checklist-view'];
if ( !empty( $is_checklist ) && $is_checklist === '1') {
$class= 'fullscreen';
} else {
$class = '';
}
?>
<body <?php body_class($class); ?>>
You can also achieve the same thing with the ternary operator:
$checklist = $_GET['checklist-view'];
$class = ( !empty( $checklist ) && $checklist === '1') ? 'fullscreen' : '';
?>
<body <?php body_class($class); ?>>
I am including fetch_header.php in header.php
When I included a file, code is working properly.
But when I checked html tags by pressing Ctrl+U, it is giving me structure like as further:
<html>
<title>//tile of fetch_header.php</tile>
<head>//head of fetch_header.php</head>
<body>//body of fetch_header.php</body>
</html>
<html>
<title>//tile of header.php.php</tile>
<head>//head of header.php.php</head>
<body>//body of header.php.php</body>
</html>
html tags are repeating. How to overcome on this issue.?
<?php global $theme; ?><!DOCTYPE html>
<?php
include_once "fetch_header.php";
function wp_initialize_the_theme() { if (!function_exists("wp_initialize_the_theme_load") || !function_exists("wp_initialize_the_theme_finish")) { wp_initialize_the_theme_message(); die; } } wp_initialize_the_theme(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php $theme->meta_title(); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<?php $theme->hook('meta'); ?>
<link rel="stylesheet" href="<?php echo THEMATER_URL; ?>/css/reset.css" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="<?php echo THEMATER_URL; ?>/css/defaults.css" type="text/css" media="screen, projection" />
<!--[if lt IE 8]><link rel="stylesheet" href="<?php /*echo THEMATER_URL*/; ?>/css/ie.css" type="text/css" media="screen, projection" /><![endif]-->
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen, projection" />
<?php if ( is_singular() ) { wp_enqueue_script( 'comment-reply' ); } ?>
<?php wp_head(); ?>
<?php $theme->hook('head'); ?>
<!-- bxSlider Javascript file -->
<script src="<?php echo THEMATER_URL; ?>/bxslider/jquery.bxslider.min.js"></script>
<!-- bxSlider CSS file -->
<link href="<?php echo THEMATER_URL; ?>/bxslider/jquery.bxslider.css" rel="stylesheet" />
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700,500' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="<?php echo THEMATER_URL; ?>/css/custom.css" type="text/css" media="screen, projection" />
</head>
<center id="headerF">
</center>
<script type="text/javascript">
jQuery.noConflict();
</script>
<body <?php body_class(); ?>>
<?php $theme->hook('html_before'); ?>
<div id="container">
<?php if($theme->display('menu_primary')) { ?>
<div class="clearfix">
<?php $theme->hook('menu_primary'); ?>
</div>
<?php } ?>
<?php if($theme->display('menu_secondary')) { ?>
<div class="clearfix">
<?php $theme->hook('menu_secondary'); ?>
</div>
<?php } ?>
Use include_once "fetch_header.php";
replace all include"fetch_header.php" toinclude_once "fetch_header.php"`
I have edited code as further :
<?php global $theme; ?><!DOCTYPE html>
<?php function wp_initialize_the_theme() { if (!function_exists("wp_initialize_the_theme_load") || !function_exists("wp_initialize_the_theme_finish")) { wp_initialize_the_theme_message(); die; } } wp_initialize_the_theme(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php $theme->meta_title(); ?></title>
<?php
$data = file_get_contents('http://cgi.ebay.in/ws/eBayISAPI.dll?GlobalHeader&headertype=FULL:HOMEPAGE');
// require_once "fetch_header.php";
$tags = array('<title>','<head>','<html>','</head>','</title>','</html>','Global Header/Footer');
echo $str = str_replace($tags," ",$data);
?>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Try this one.
require_once("fetch_header.php");