how do i echo a value from php to html in a division (div2--a div i created) of a paragraph(p).
for example: i have a value called $greetings and i assign a value of "Welcome" to it
$greetings = "Welcome";
I tried:
`<p>
<?php
$index = "WELCOME";
echo "<div2>$index</div2>";
?>
</p>`
but it doesn't display the value of $greetings--welcome
instead it displays ( $index"; ?> )
HERES MY ENTIRE CODE:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Tech Planet</title>
<link rel="stylesheet" type="text/css" href="style.css">
<img src="logo.gif" alt="logo" width="150" height="50">
<div class ='seachAndProducts'><form action="header.php" method="GET">
<input id="search" type="text" placeholder="Search Tech Planet...">
<input id="submit" type="submit" value="Search">
</form></div>
<div class = 'navAndFooter'><ul>
<li><b>Home</b></li>
<li><b>Products</b></li>
<li><b>About</b></li>
<li><b>Contact us</b></li>
</ul></div>
<img src="cart.jpg" alt="cart" width="40" height="40">
</head>
<body>
<h3><img src="WelcometoTechPlanet.gif" width="250" height="40"></h3>
<h5><div class ='ourAndFeatProductsHeader'>Our Products</div>
<div class='seachAndProducts'>
<div class='ourProductsList'>Audio Systems</div>
<div class='ourProductsList'>Cameras</div>
<div class='ourProductsList'>Laptops</div>
<div class='ourProductsList'>Memory Cards</div>
<div class='ourProductsList'>Monitors</div>
<div class='ourProductsList'>Phones</div>
<div class='ourProductsList'>Televisions</div>
<div class='ourProductsList'>USBs</div>
<div class='ourProductsList'>All Products</div>
</div><div class ='ourAndFeatProductsHeader'>Featured Products</div>
<div2><img src="8wb50.gif" alt="" width="250" height="200"></div2></h5>
<p><?php
$index = "WELCOME";
echo "<h1>$index</h1>";
?></p>
<!-- used © because © displays © -->
<div class = 'navAndFooter'>© Tech Planet. All Rights Reserved.</div>
</body>
</html>
Here are a few things to note...
Don't put an h1 tag in the p tag; and you are echoing $index, not $greetings.
Try this
<?php
// Pick the one you want.
$greetings = "Welcome";
$index = "WELCOME";
// Pick the one you want
echo "<h1>$index</h1>";
echo "<h1>$greetings</h1>";
?>
Then, make sure you save it as a .php file, and that you are on a web server with php enabled.
Related
how can I automatically save this pizza image, and save it to my local folder? I can easily save the other information, but I'm encountering automatically saving the image itself in a local folder?
I'm fetching the other data from different table, but the I can't save the image itself. I'm have no intention of using foreign key for no.
backend.php
if (isset($_POST['addcart'])) {
$con = connection();
$fetch = singleInfo();
$name = $fetch['name'];
$price = $fetch['price'];
$image = $fetch['image'];
$new_image = '../images/' . $image;
$stmt = $con->prepare("INSERT INTO `cart`(`name`, `price`,`image`) VALUES ('$name','$price','$new_image')");
$stmt->execute();
}
index.php
<?php
session_start();
require('../backend/clientbackend.php');
$fetch = singleInfo();
$current_price = $fetch['price'];
?>
<!DOCTYPE html>
<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.0">
<link rel="stylesheet" href="./style/style.css">
<title>E-Commerce</title>
</head>
<body>
<nav>
<div class="left">
<h4 class="navbar-header"> Branding </h4>
<ul>
<li>Home</li>
<li>Shop</li>
<li>About</li>
</ul>
</div>
<div class="right">
<button class="loginButton">Login</button>
</div>
</nav>
<article>
<form method="post" class="product-description">
<div class="left">
<div class="left-title" name="name"> <?php echo $fetch['name']; ?> </div>
<div class="left-info">
<p class="left-description"> <?php echo $fetch['desc']; ?> </p>
<span class="price" name="price"> $ <strong> <?php echo $fetch['price']; ?></strong> </span>
</div>
<div class="left-increment">
<div class="addition">+</div>
<input type="number" class="current_value" value="1" min="1">
<div class="subtraction">-</div>
<button class="gotoCart" name="addcart" type="submit"> Add To Cart </button>
Go to cart
</div>
</div>
<div class="right">
<div class="right-image">
<img name="image" src="<?php echo '../uploads/' . $fetch['image']; ?>" alt="">
</div>
</div>
</form>
</article>
<footer>
<div class="footer-container">
<div class="box1">
<h3>Ecommerce Branding</h3>
<span>School Activity</span>
</div>
<div class="box2">
<h3>Colegio De San Lorenzo
</h3>
<span>Congressional Ave, Project 8, Quezon City, Metro Manila</span>
</div>
<div class="box3">
<h3>Emman Cruz</h3>
<span> zurcemozz#gmail.com</span>
</div>
</div>
</footer>
<script>
const addBtn = document.querySelector('.addition');
const subBtn = document.querySelector('.subtraction');
let currentValue = document.querySelector('.current_value');
let stock = 1;
addBtn.addEventListener("click", function() {
stock = stock + 1
currentValue.value = stock;
console.log(currentValue.value);
})
subBtn.addEventListener("click", function() {
if (stock <= 0) {
stock = 0;
} else {
stock = stock - 1
currentValue.value = stock;
console.log(currentValue.value);
}
})
</script>
</body>
</html>
you can copy the image file from '../uploads/' to '../images/' and then you save it .
you can do this with copy function
copy documentations
copy() example :
<?php
$image = '../uploads/'.$fetch['image'];
$new_image= '../images/'.$fetch['image'];
if (!copy($image , $new_image)) {
echo "failed to copy $image ...\n";
}
?>
I need a code that displays the IP of the person/guest that commented on my website.
Here's the index page;
<?php
include "core/init.php";
?>
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="http://hjalplista.comxa.com/daniel_emelie/style.Css">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Välkommen till hjälplistan!</title>
<body>
<div id="header">
<div align="right"><img src="http://i.imgur.com/y0aiNIt.jpg"></div>
</div>
<div id="inside">
<center>
<div id="location"><a href='index.php'>Hem</a> - <a href='administrative/adminonlyaccess.php'><i>Admin</i></a><br><br>
</div>
<hr/>
<br>
<div id="text">
<br>
<table border="1" cellpadding="1" cellspacing="1" style="width: 100%;">
<tbody>
<tr>
<td><span style="color:slategray;"><strong><center>Nr</center></strong></span></td>
<td><span style="color:slategray;"><strong><s><center>Fått hjälp</center></s></strong></span></td>
<td><span style="color:slategray;"><strong><center>Namn</center></strong></span></td>
<td><span style="color:slategray;"><strong><center>Uppgift</center></strong></span></td>
<td><span style="color:slategray;"><strong><center>IP-Adress</center></strong></span></td>
</tr>
<?php
include "core/inc/conn.php";
mysql_select_db("comments");
$getquery = mysql_query("SELECT * FROM comments ORDER BY id DESC");
while($rows = mysql_fetch_assoc($getquery))
{
$id = $rows['id'];
$comment_name = $rows['name'];
$comment = $rows['comment'];
echo"<tr><th><font color='lightgray'>$id</font></th>";
echo"<th><font color='red'>Fungerar ej!</font></th>";
echo "<th><u><font color='black'>$comment_name</font></u></th>";
echo"<th><font face='black'>$comment</font></th>";
echo"<th></th></tr>";
}
if(isset($_GET['error']))
{
echo "<p>15 Bokstäver max!";
}
?>
</table>
<br><br>
</body>
<head>
<center>
</div>
<br><br>
<form action="post_comment.php" method="post">
<label> Namn: <input type="text" name="name"></label><br><br>
<label> Uppgift: <input type="text" name="comment"></label><br><br>
<input type="submit" name="post" value="Skicka">
</form>
<br><br>
<br><br>
<?php
echo "<br><br><br>";
echo "<hr/>";
echo "<p> © Wieselgrenskolan. All rights reserved. </p>";
?>
</head>
</html>
<html>
<div align="right">
<!-- START OF HIT COUNTER CODE -->
<br><script language="JavaScript" src="http://www.counter160.com/js.js?img=11"></script><br><img src="http://www.counter160.com/images/11/left.png" alt="Free web hosting" border="0" align="textright"><img alt="Web hosting" src="http://www.counter160.com/images/11/right.png" border="0" align="texttop">
<!-- END OF HIT COUNTER CODE -->
</div>
</html>
And it's supposed to be in the echo "<th></th></tr>";. Do I need a MySQL table for that?
I've created a index in mysql called ''commentip'' but I don't know how to fix the missing parts.
You can get the IP in php in most cases using $_SERVER['REMOTE_ADDR'] However if they are using a proxy or you are using a reverse proxy like cloudflare or incapsula then you can use $_SERVER['HTTP_X_FORWARDED_FOR'].
I'm currently learning PHP and am creating a small CMS feature that includes a login area. I have used the code below which includes an include header file that contains the doctype/head info and the opening tag. It also includes the header content. I also have a connection file for connecting to the db.
My header include code is:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title><?php echo $pagetitle ?></title>
<link rel="stylesheet" href="../stylesheets/foundation.css">
<link rel="stylesheet" href="../stylesheets/app.css">
<style>#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800); #import url (http://fonts.googleapis.com/css?family=Kreon:100,200,300,400);</style>
<script src="../javascripts/modernizr.foundation.js"></script>
</head>
<body>
<div class="subHeader">
<div class="row">
<div class="four columns logo">
<img src="../images/logo.png" alt="logo" />
</div>
<div class="eight columns navigation right">
<ul class="navigationMain">
<li class="<?php if($navcurrent == "home"){echo "navigationActive";} ?>">Home</li>
<li class="<?php if($navcurrent == "services"){echo "navigationActive";} ?>">Services</li>
<li class="<?php if($navcurrent == "work"){echo "navigationActive";} ?>">Recent Work</li>
<li class="<?php if($navcurrent == "about"){echo "navigationActive";} ?>">About</li>
<li class="<?php if($navcurrent == "contact"){echo "navigationActive";} ?>">Contact</li>
</ul>
</div>
<div class="twelve columns titlesection">
<h2><?php echo $headTitle ?></h2>
<h4><?php echo $headsubTitle ?></h4>
</div>
</div><!--End Feature Row-->
</div><!--End Feature-->
<div class="underbar">
<div class="bordertriangle"></div>
<div class="row">
<div class="eight columns"> </div>
<div class="three columns right socialcontainer">
<ul class="socialicons">
<li><a><img id="linkedinIcon" src="../images/socialli.png" alt="linkedin icon" /></a></li>
<li><a><img id="twitterIcon" src="../images/socialtw.png" alt="twitter icon" /></a></li>
<li><a><img id="facebookIcon" src="../images/socialfb.png" alt="facebook icon" /></a></li>
</ul>
</div>
</div>
When I open the admin page, the username password form, header and footer appear as they should. If I test the errors, they return as they should. However, when I successfully log in using a valid username and password, no content appears except the what is included in the header file. Can anyone point me in the direction of what i might be doing wrong? Any help would be much appreciated. I am a relative noob to PHP...
<?php
$pagetitle = "Admin";
$navcurrent = "home";
$headTitle = "ADMIN AREA";
$headsubTitle = "SITE ADMINISTRATION AREA";
include_once('../includes/connection.php');
include_once('../includes/headeradmin.php');
if (isset($_SESSION['logged_in'])) {
echo('Successfully Logged In');
} else {
if (isset($_POST['username'], $_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) or empty($password)){
$error = 'An Error Has Occurred - All Fields Are Required';
}
else{
$query = $pdo->prepare('SELECT * FROM users WHERE user_name = ? AND user_password = ?');
$query->bindValue(1, $username);
$query->bindValue(2, $password);
$query->execute();
$num = $query->rowCount();
if ($num == 1) {
$_SESSION['logged_in'] = true;
header('location: index.php');
exit();
}
else{
$error = 'The username/password you entered was incorrect - Please try again';
}
}
}
?>
<div class="row">
<div class="four columns centered">
<?php if (isset($error)) { ?>
<h5 style="color: #e63333;"><?php echo $error; ?></h5>
<br />
<br />
<?php } ?>
<form action="index.php" method="post">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Login" />
</form>
</div>
</div>
You can't use the header('location: index.php'); line if you've already output content (i.e - html code) to the browser when you included the header in this line include_once('../includes/headeradmin.php');
read the documentation of header - Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP
you need to redirect the user with the header() function before you output the head html of the admin page
i'm working on a form in php mysql. so in my page there is a form and below that i shown the data of that form in table format.now i want to print only the table structure thats why i just made a PRINT button as:
<span style="float:right;">PRINT</span>
but it will print the whole page with form field and table and i just want the tableto print.
Here is the design of my whole page with form and table:
<html>
<head></head>
<body>
<div class="container">
<form class="form-horizontal" action="" method="post" name="userform1" id="company-form" enctype="multipart/form-data">
<?php if($_GET[id]){?>
<fieldset>
<legend>Add Company</legend>
<div class="control-group">
<label class="control-label">Company Name</label>
<div class="controls">
<input type="text" name="company" id="company" value="<?php echo $selup['company']?>">
</div>
</div>
<div class="control-group">another field</div>
<div class="control-group">another field</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit" id="submit" value="Submit">Submit</button>
</div>
</div>
<table class="table table-bordered">
<tbody>
<tr>
<td>S.No.</td>
<td>Company Name</td>
<td>Type</td>
<td>Action</td>
</tr>
<?php
// to print the records
$select = "select * from company where type='Miscellaneous'";
$query1 = mysql_query($select);
while($value = mysql_fetch_array($query1)){ ?>
<tr>
<td><?php echo $value[id];?></td>
<td><?php echo $value[company ];?></td>
<td><?php echo $value[type];?></td>
<!--<td> </td>-->
<?php /*?><td><?php echo $value[amount];?></td>
<td><?php echo $value[date];?></td><?php */?>
<td><i class="icon-edit"></i>
<i class="icon-trash"></i></td>
</tr><?php }?>
</tbody>
</table>
</fieldset>
<form>
</div>
</body>
so i just want to print the table not whole page.
Use css to hide elements you don't want to print:
#media print {
.control-group {
display: none;
}
}
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>My page</h1>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
<div id="div2">DIV 2 content...</div>
<button onclick="printContent('div2')">Print Content</button>
<p id="p1">Paragraph 1 content...</p>
<button onclick="printContent('p1')">Print Content</button>
</body>
</html>
You could make a print-css (which does the same as #media print, but I think it is cleaner, and you can disable the css include via javascript, if you need it):
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
In that css, you hide all elements which should not get printed, for example:
.wrapper, .header {display: none;}
One posible solution, perhaps not the best option:
1. Open a new window with JS
2. Copy the whole table into the new window (with jQuery for example)
3. Print the new window
4. Close the window
Sure it has a blink effect but It will work.
I have just searched the document to find it, I removed the <hr class="cmdbar"></hr> but it is still there! Do any of you see anything else?
<?php print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<font face="Segoe UI">
<body>
<script type="text/javascript">
/*function detectBrowser()
{
var browser = navigator.appCodeName;
if (browser!="Mozilla") {document.location.href="noaccess.php"; alert(browser);}
}
detectBrowser();
*/
</script>
<title>Second</title>
<link rel="stylesheet" type="text/css" href="allCSS.css"/>
<center>
<!--<img align="right" src="logo.png" id="headerimg"/>-->
<input type="image" id="headerimg" src="logo.png" align="right" onclick="toggleh();"/>
<ul align="center" class="">
<div class="menu">
<ul class="nav">
<li><strong>Home</strong>
<ul>
<li>Games</li>
<li>Browse</li>
<li>Catalogue</li>
<li>Forums</li>
</ul>
</li>
<li><strong>Games</strong>
<ul>
<li>Profile</li>
<li>Settings</li>
</ul>
</li>
<li><strong>Contact</strong>
<ul>
<li>Phone</li>
<li>Email</li>
<li>Mail</li>
</ul>
</li>
</div>
</center>
</body>
<center>
<?php
echo '<div id="msg">';
include 'message.txt';
echo '</div>';
//include 'hits.txt';
?>
<p>
<?php
function ChangeText($txt)
{
$txt='<script type="text/javascript">get();</script>';
echo '<script type="text/javascript">change();</script>';
$filename="message.txt";
$fp=fopen($filename,'w');
fwrite($fp,'<h4 class="hmsg">' . $txt . '</h4>');
fclose($fp);
}
?>
<script type="text/javascript">
<!--
window.onload=enter;
function enter()
{
//alert("Welcome!");
//hideCMD();
}
function get(text)
{
text=document.getElementById("ta").value;
return text;
}
function toggleh()
{
var element=document.getElementById("headerimg");
if (element.style.display!="none"){element.style.display="none";}
else {element.style.display="";}
}
function change(text)
{
text=document.getElementById("ta").value;
if (text=="toggle") {toggleh(); return;}
if (text=="home") {document.location.href="index.html"; return;}
if (text.match("goto:*")) {var loc=text.substring(5,text.length); document.location.href=loc; return;}
if (text.match("ban:*")) {var loc=text.substring(4,text.length); document.location.href=loc; return;}
document.getElementById("msg").innerHTML='<h2 class="hmsg">'+text+'</h2>';
}
function hideCMD()
{
document.getElementById("cmd").style.display="none";
}
//-->
</script>
</head>
<body>
<div id="msg">
</div>
<p id="cmd">
<input class="panela" type="text" value="" id="ta" maxLength="20"/>
<input class="panelb" type="image" src="submit.png" alt="Submit" onclick='change();'/>
</p>
</center>
<p class="hide">-</p>
</font>
</html>
Here it is <hr class="cmdbar"></hr>, line: 126. CTRL + F generally works with most text editors.
Here it is:
<p id="cmd">
<hr class="cmdbar"></hr>
<input class="panela" type="text" value="" id="ta" maxLength="20"/>
<input class="panelb" type="image" src="submit.png" alt="Submit" onclick='change();'/>
</p>
Browsers do treat <hr></hr> as a proper <hr /> too, although that's not supposed to be so according to W3C specs.
You could also use Firebug for Firefox. It's a neat add-on that helps you find code based on the appearance of the web page.