I'm trying to load part of a targeted URL ($url) into my HTML page, currently the $url page sends back a name, model, type and self recalculate tool - all of which live in a HTML TR tags.
Once I post my daily password from password.php than my users click on $url to get their daily inventory from it, again and i don't mean to be redundant, but the $url itself is provided to me by my clients and I don't want my users to be able to see all the links on that page - Only what pertain to their job.
Also rather than me creating password.php is there a way for me to "collect" this password from my daily outlook exchange email and post it to the header of the $url??
Many thx and I hope i was descriptive enough.
<html>
<head>
<title>Post Password</title>
</head>
<body>
<?php
$password = "";
?>
<form name="password" method="post" action="users.php">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>Paste the Daily Password</td>
<td><input type="text" maxlength=7 name="password"></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<title>First Page</title>
</head>
<body>
<?php
$url_append = "?secret=";
//$psk = $password;
$linktext = "Click here to get a Pre Shared Key";
$password = $_POST["password"];
$url = "http://example.subexample.xx.com/";
$url .= $url_append;
$url .= $password;
$final_url = $url;
// end base users
?>
<!--I took this form below from the URL that my client host-->
<!--His url have way more input than all_products-->
<!-- but that's the only one that I want to echo for my employees to use -->
<form name="form1" method="post" action="<?php echo htmlspecialchars($final_url);?>">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>Main Inventory</td>
<td><input type="text" maxlength=7 name="all_products"></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
For sending POST through header take a look at this.
As for the omitting the parts of html, you can use alternative syntax like this
<?php if ($a == 5): ?>
<p>This will be omitted if condition is not true</p>
<?php endif; ?>
Similar can be used for for loop.
Read more on alternative syntax.
Related
I want to write a basic form with inputs that executes an external php file. That file should do some calculations with the inputs and append the output to a table.
My HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Prices</title>
</head>
<body>
<form name="priceform" method="get" action="add-item.php">
<input name="item_name" placeholder="Item Name">
<input name="amount" placeholder="Amount">
<input name="price_per_unit" placeholder="Price per Item">
<button type="submit" name="submit">Submit</button>
</form>
<div id="pricetable">
<table>
<thead>
<tr>
<th>Name</th>
<th>Amount</th>
<th>Netto</th>
</tr>
</thead>
<tbody>
<!-- Append rows here -->
</tbody>
</table>
</div>
My PHP Code
<?php
$item_name = $_GET["item_name"];
$amount = $_GET["amount"];
$price_per_unit = $_GET["price_per_unit"];
//do calculations
echo "
<tr>
<td>$item_name</td>
<td>$amount</td>
<td>$price_per_unit</td>
</tr>";
?>
I want the table row to append to my table in the html file.
Thanks for the help in advance.
You can merge these files together, or if you want external php file, you can just call it like this:
index.php:
...
<div id="pricetable">
<table>
<thead>
<tr>
<th>Name</th>
<th>Amount</th>
<th>Netto</th>
</tr>
</thead>
<tbody>
<?php include "calculate.php";?>
</tbody>
</table>
</div>
...
calculate.php is that calculation php file.
You can do this in two ways:
save the previously added lines somewhere (session, database?) and load them each time you refresh the page, adding a new line at the end with new data (and of course, re-save them with this new data)
or each time send previously added lines in the form. So you need to add a lot of hidden values to the form in which all previously submitted values will be stored.
I have the following php page in which I am trying to simulate a simple example of searching for a specific username (stored in the database) and when "submit" is clicked, the results for that user are displayed on the page. At the moment, the code shows the results displayed only for the user that is logged in. How do I adapt it to fit with the code to search and track as another user?
HTML:
<p>Welcome, teachers! Here you can track student progress.</p>
<p>Enter the username of the student you wish to 'view' results for</p>
<form action="/action_page.php">
Username: <input type="text" name="FirstName" value="Mickey"><br>
<input type="submit" value="Submit">
</form>
Php related code that only allows the page to load if the user is logged in:
session_start();
if (!isset($_SESSION['username']) or ($_SESSION['username'] == '')) {
header("Location: login.php");
}
?>
Php code that displays the currently logged in user's quiz results:
<table class="table table-hover" style="text-align:center;">
<thead>
<tr>
<th style="text-align:center;">Quiz</th>
<th style="text-align:center;">Score (%)</th>
<th style="text-align:center;">Certificate</th>
<th style="text-align:center;">Retake</th>
</tr>
</thead>
<tbody>
<?php
$a = new NewQuizScore;
$scores = $a->getScores($_SESSION['username']);
foreach ($scores as $score) {
echo ("<tr>");
echo ("<td>".$score[0]. "</td> ");
echo ("<td>".$score[1]. "</td> ");
echo ('<td>Print Certificate</td>');
echo ("<td>Take it again!</td> ");
echo ("</tr>");
}
?>
</tbody>
</table>
</div>
</div>
To reiterate, as a php newbie, I would like a solution (with code in my existing context provided) for how to use the search button to look up a username, and then provide the information for the SEARCHED FOR username in the page, rather than for the username that is logged in. I've tried various things and cannot come up with the logic.
What I've tried:
Along the lines of:
<form action="/action_page.php">
Username: <input type="text" name="username1" value="username1"><br>
and:
$a = new NewQuizScore;
$scores = $a->getScores($_SESSION['username1']);
I was trying to link what is entered in the text box, to the getScores session, but obviously this doesn't work:
Update based on suggested answer - still doesn't work:
<?php
require 'includes/functions.php';
include_once 'config.php';
include 'includes/newquizscore.php';
session_start();
if (!isset($_SESSION['username']) or ($_SESSION['username'] == '')) {
header("Location: login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="#" method="post">
Username: <input type="text" name="username1" value=""><br>
<input type="submit" value="Submit">
</form>
<?php
$username = (!empty($_POST['username1']))? $_POST['username1'] : $_SESSION['username'];
$a = new NewQuizScore;
# This is assuming this action is what you use to get the user's data
$scores = $a->getScores($username)
?>
</body>
</html>
You need to get the value from the form using the $_POST superglobal. $_POST is less transparent than $_GET, so I would use that for your form:
<!-- ADD METHOD ------------------------------->
<!------------------------------vvvvvvvvvvvvv-->
<form action="/action_page.php" method="post">
Username: <input type="text" name="username1" value=""><br>
<input type="submit" value="Submit">
</form>
When you post the form, you can use the script below. Note, since your form is pointing to /action_page.php, that is where this script should be located:
# Fetch the post value OR the current logged in (depending if form submitted or not)
# This is assuming you are searching by username1 value from form
# (since that is what you have in your form). You can use functions like
# trim() to remove empty spaces before and after submitted value to clean
# the input up a bit
$username = (!empty($_POST['username1']))? $_POST['username1'] : $_SESSION['username'];
$a = new NewQuizScore;
# This is assuming this action is what you use to get the user's data
$scores = $a->getScores($username);
I have this form in which there is only one field i.e. "Email id", so what I have to do is that when I entered the email id the email id must be split into two parts like user name and domain name and must be displayed in next form.
So my problem is that my 2nd form doesn't display the result, however when I used $_SESSION method in place of $_POST(to take value of email field) it takes the value and also split it but takes only one value as I want to take multiple email ids.
For better understanding please check my code.
<?php
session_start();
?>
<!Doctype html>
<html>
<head>
<title>PHP3</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron">
<div class="container">
<form class="form-horizontal" method="post" action="screen3_controller.php">
<div class="form-group">
<label class="control-label col-sm-2" for="email_text">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="email_text" id="email_text">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" name="submit" id="submit_button" class="btn btn-default" value="Submit">
</div>
</div>
</form>
</div>
</div>
<table class="table table-striped table-responsive">
<thead>
<tr>
<th>Email Id</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_SESSION['all_post']) && !empty($_SESSION['all_post']))
{
foreach($_SESSION['all_post'] as $key=>$value)
{
?>
<tr>
<td><?php echo $value['email_text']; ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<div class="container">
<table class="table table-bordered">
<thead>
<tr>
<th>User Name</th>
<th>Domain Name</th>
</tr>
</thead>
<tbody>
<?php
$str = $_POST['email_text'];
$hello = explode("#", $str);
$_SESSION ['emails'] = $hello;
echo "<tr>";
foreach ($_SESSION ['emails'] as $value)
{
echo "<td>$value</td>";
}
echo "</tr>";
?>
</tbody>
</table>
</div>
</body>
</html>
Controller:
<?php
session_start();
$data = $_POST;
if (isset($data['submit'])) {
$_SESSION['all_post'][] = $data;
}
header('Location:screen3_2.php'); exit();
?>
As I can see,
In your code you are posting your form data to controller, not the second page.
Though you are storing your data to $_SESSION in your controller page, That's how you're able to access data from second page.
Solution :
either access data on second page using $_SESSION, or
POST your first page to directly second page, and access data using $_POST.
When the following code executes, it does NOT send the POST vars with it.
They are lost at that point. However, you have stored the data in the session.
header('Location:screen3_2.php'); exit();
Also note that the following code:
$str = $_POST['email_text'];
$hello = explode("#", $str);
$_SESSION ['emails'] = $hello;
Will store the two parts of exactly one email. You mentioned that you want to store multiple emails and this code will not accomplish that.
It seems to me that what you want to do is to keep going back to the same page and reusing the form while collecting email addresses. Please confirm.
Try this:
Do not use a separate controller file. Take that code and remove the redirect. Put that code at the top of the file. This way you collect
all the email addresses from $_POST.
<?php
// Taken from 'controller'
session_start();
// Only process post if it exists
if ( ! empty($_POST) ) {
$data = $_POST;
if ( isset($data['submit']) ) {
$_SESSION['all_post'][] = $data;
}
}
// No redirect
?>
<?php // put the form here ?>
<form class="form-horizontal" method="post" >
<input type="email" class="form-control" name="email_text" id="email_text">
<input type="submit" name="submit" id="submit_button" class="btn btn-default" value="Submit">
</form>
<?php
// output all the email addresses collected
if(isset($_SESSION['all_post']) && !empty($_SESSION['all_post'])) {
foreach($_SESSION['all_post'] as $key=>$value) {
$parts = explode('#', $value['email_text']);
?>
<tr>
<td><?= $parts[0] ?></td> <?php // before # ?>
<td><?= $parts[1] ?></td> <?php // after # ?>
</tr>
<?php
}
}
?>
</form>
Each time i tried to log in through : webhost/adminlogin.php , am redirected back to thesame page. Is there any thing i forgot to add? Thank you for your help.. Here is my script below
This is my adminlogin.php
<?php session_start(); if(isset($_SESSION[ 'admin_login'])) header( 'location:admin_homepage.php'); ?>
<!DOCTYPE html>
<html>
<head>
<noscript>
<meta http-equiv="refresh" content="0;url=no-js.php">
</noscript>
<meta charset="UTF-8">
<title>Admin Login - Online Banking</title>
<link rel="stylesheet" href="newcss.css">
</head>
<?php include 'header.php'; ?>
<div class='content'>
<div class="user_login">
<form action='' method='POST'>
<table align="center">
<tr>
<td><span class="caption">Admin Login</span>
</td>
</tr>
<tr>
<td colspan="2">
<hr>
</td>
</tr>
<tr>
<td>Username:</td>
</tr>
<tr>
<td>
<input type="text" name="uname" required>
</td>
</tr>
<tr>
<td>Password:</td>
</tr>
<tr>
<td>
<input type="password" name="pwd" required>
</td>
</tr>
<tr>
<td class="button1">
<input type="submit" name="submitBtn" value="Log In" class="button">
</td>
</tr>
</table>
</form>
</div>
</div>
<?php include 'footer.php'; ?>
<?php include '_inc/dbconn.php'; if(!isset($_SESSION[ 'admin_login'])){ if(isset($_REQUEST[ 'submitBtn'])){ $sql="SELECT * FROM admin WHERE id='1'" ; $result=mysql_query($sql); $rws=m ysql_fetch_array($result); $username=m ysql_real_escape_string($_REQUEST[
'uname']); $password=m ysql_real_escape_string($_REQUEST[ 'pwd']); if($username==$rws[8] && $password==$rws[9]) { $_SESSION[ 'admin_login']=1; header( 'location:admin_hompage.php'); } else header( 'location:adminlogin.php'); } } else { header(
'location:admin_hompage.php'); } ?>
I think there may be a few issues with your script. One obvious one is that you are outputting html content before you send the headers at the bottom of the script.
HTTP headers must be sent to the client before any other content.
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. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
I would suggest that unless you need to continue processing. You move all your login code to the top of the script and call 'exit()'; after you have sent the headers to the client to prevent any further processing or content being sent to the client.
i try to solve a problem but didnt succeed. I retrieve datas from google analytics and i have to send start and end date. I have two textbox and user select start and end date.However, but before user select start and end date. The problem occurs..
The place that i use isset is here,
This is my full html
<?php
define('ga_email','mertmetinbjk#gmail.com');
define('ga_password','************');
define('ga_profile_id','*******');
require 'gapi.class.php';
require 'connectDB.php';
$ga = new gapi(ga_email,ga_password);
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>İçerik</title>
<script language="javascript" type="text/javascript" src="datetimepicker.js">
//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com
</script>
</head>
<div></div>
<body>
<table align="center">
<tr>
<td><br />
<br />
<form action="#" method="post" name="formDates" id="form1" >
<table width="303" height="40" border="0" align="center">
<table width =""
<tr>
<td>Başlangıç Tarihi</td>
<td>
<label for="txtStartDate"></label>
<input type="text" name="txtStartDate" id="txt1" value="" /><a href="javascript:NewCal('txt1','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Başlangıç Tarihi Seçin">
</a>
</td>
</tr>
<tr>
<td>Bitiş Tarihi</td>
<td>
<label for="txtEndDate"></label>
<input type="text" name="txtEndDate" id="txt2" /><a href="javascript:NewCal('txt2','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Bitiş Tarihi Seçin">
</a>
</td>
</tr>
</form>
<tr>
<td><input type="submit" name="btnSubmit" value="Gönder"</td>
</tr>
</table>
<table width="1250" height="26" align="center">
<tr>
<td width="138"><strong>Kanal Adı</strong>
<td width="150"><b>Kategori Adı</b></td>
<td width="130"><p><strong>Event Adı</strong></td>
<td width="145"><strong>Toplam</strong>
</tr>
</table>
<?php
if(isset($_POST['submit'])){
$startDate = $_POST['txtStartDate'];
$endDate = $_POST['txtEndDate'];
}
$arrDates = explode("-",$startDate);
$startDate=$arrDates[2]."-".$arrDates[1]."-".$arrDates[0];
$arrDates = explode("-",$endDate);
$endDate = $arrDates[2]."-".$arrDates[1]."-".$arrDates[0];
echo $startDate;
echo $endDate;
$ga->requestReportData(ga_profile_id,array('eventCategory','eventAction'),array('totalEvents'),$sort_metric=null,$filter='eventAction==InitPlayer',$start_date='2012-02-02',$end_date='2012-02-16');
foreach($ga->getResults() as $result2);
{
echo $result2->geteventCategory();
echo $result2->geteventAction();
echo $result2->gettotalEvents();
}
$ga->requestAccountData();
$mysql = new mysql();
$mysql->connect();
$counter = 0;
foreach($ga->getResults() as $result)
{
echo $result . ' (' . $result->getProfileId() . ")<br />";
echo "<br />";
$counter++;
}
$result = mysql_query("select profile_id from profiles");
$num_rows = mysql_num_rows($result);
if($counter != $num_rows)
{
$mysql->query("delete from profiles");
foreach($ga->getResults() as $result)
{
$mysql->query("insert into profiles values(".$result->getProfileId().",'".$result."')");
}
}
?>
</td>
</tr>
</table>
</body>
</head>
</html>
what is wrong?
if a choose start and end date problems is solved , problems occurs before that i choose
It must be isset($_POST["btnSubmit"]) NOT submit
submit = type
btnSubmit = name of the button
I think it should be:
if(isset($_POST['submit']))
instead of:
if(!isset($_POST['submit']))
The exclamation mark in front of isset means not. Also I would check for the actual fields you want to use, not for $_POST['submit']:
if(isset($_POST['txtStartDate']) && isset($_POST['txtEndDate']))
{
// Do something with $_POST['txtStartDate'] and $_POST['txtEndDate']
}
The reason you were getting the error is that $_POST['submit'] does not exist. There is not input element with a name attribute called submit. Beware of the difference between type and name.
Undefined index txtStartDate, ...
It seems that your form may not be conforming to the same variable name specification with the one that you use in this php file. Make sure field names are matching within the form and here.
And also you should make these checks in your php file after submission success: if(!isset($_POST['submit']))
When your page is loading and $_POST['submit'] is not set, your $_POST['txtStartDate'] and $_POST['txtEndDate'] are not set so $arrDates is not set too. You need to check if these $_POST vars are set or not, to work with them.
You have to use isset() on every variable, not just one variable. $_POST['txtStartDate'] and $_POST['txtEndDate'] and other variables are simply not defined, this means that they were not sent with the POST request.
I guess it should be if(isset($_POST['submit'])) instead of if(!isset($_POST['submit'])) as ! in the start means a negation
if(!isset($_POST['submit']))
This means that if the submit button was NOT pressed. You should check if the $_POST['submit'] is set, as a result of the form submission, like so:
if(isset($_POST['submit']))