PHP variable add another page - php

I have two websites. I would like to simply echo message on the second page (example: echo "FOO") at the commented place on the first page. How can I solve it?
Second page: msg.html
echo "foo";
First page: index.php
<form id="form_1" method="post" action="dbconn.php">
<table id="table_form">
<tr>
<td colspan="2" id="table_main">Jelentkezés</td>
</tr>
<tr>
<td>Név</td>
<td><input class="text_box" type="text" name="nev" placeholder="Név"></td>
</tr>
<tr>
<td>E-mail cím</td>
<td id="bubble_pos"><input class="text_box" type="text" name="email" placeholder="Email cím">
<div id="bubble_box">
<div class="bubble"><?php echo ///////////;?></div>
</div>
</td>
</tr>

Related

Preserve form values from page to page

I have two PHP pages from one I input the year and after submitting year value goes in next page via form input as in image enter image description here
image just after clicking the submit button of first page
code for the first page is
<div class="col-sm-12" style="background-color:lavender;">
<form method="post" action="next.php">
<table id="emi" width="100%">
<tr>
<td width="100%">
<div align="center"><b>
<h3> Enter Fiancial Information:</h3>
</b> </td>
<table width="100%" border="0" id="emi">
<tr>
<td><strong>First Calender Year of DATA! ( i.e. 1999 ) </strong></td>
<td><input type="text" class="form-control" placeholder="Enter the First Assesment Year" name="year" pattern="\d*" maxlength="4"></td>
<td><input type="submit" value="Go" name="submit"class="btn btn-success"></td>
</tr></table>
</table></form>
</table>
I have two PHP pages from one I input the year and after submitting year value goes in next page via form input as in image enter image description here
In next page I have one form input also and after input the values in next page and after clicking compute button the value of year which we call from page one disappear. As shown in image
Image after clicking the compute button on next.php
code for the next.php which is called after the first page is
<?php
error_reporting(0);
$year=$_REQUEST['year'];
$x=$year+1;
$y=$x+1;
?>
<table id="emi"width="100%">
<tr>
<td width="40%"><strong>INCOME STATEMENT
</strong></td>
<td width="20%"><strong> 31-03-<?php echo $year;?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $x?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $y?></strong></td>
</tr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<table id="emi" width="100%">
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a1" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a2" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
</table>
<table id="emi" width="100%">
<tr>
<td colspan="3">
<center>
<input type="submit" value="Compute" name="submit"class="btn btn-success"></center>
</td>
</tr>
</table>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=="POST"){
$a=$_POST['a1'];
$b=$_POST['a2'];
echo $a+$b;
}?>
I have only call the value of year then plus one in it as you see 2000 2001 2002 to next page and when I enter the value of sundry it disappears the value of year and we get only plus means value of year become 0 after clicking the compute button.
When you submit the form on the second page via your "Compute" button $_REQUEST['year'] is no longer set because it was from the previous request.
One way around this would be to add a hidden input field which stores the $_REQUEST['year'] value for the next request.
Something like this should work:
<input type="hidden" name="year" value="<? echo $_REQUEST['year']; ?>">
replace your next.php with this code
<?php
error_reporting(0);
$year=$_REQUEST['year'];
if($year==null){
$year=$_POST['year'];
}
$x=$year+1;
$y=$x+1;
?>
<table id="emi"width="100%">
<tr>
<td width="40%"><strong>INCOME STATEMENT
</strong></td>
<td width="20%"><strong> 31-03-<?php echo $year;?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $x?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $y?></strong></td>
</tr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<table id="emi" width="100%">
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a1" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a2" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
</table>
<table id="emi" width="100%">
<tr>
<td colspan="3">
<center>
<input type="hidden" id="year" name="year" value="<?php echo($year);?>">
<input type="submit" value="Compute" name="submit"class="btn btn-success"></center>
</td>
</tr>
</table>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=="POST"){
$a=$_POST['a1'];
$b=$_POST['a2'];
echo $a+$b;
}?>

Form action attribute does not work

There is problem in submitting the form. My form tag looks like-
<form method="post" action="classes/action.php" >
this doesn't redirect the page..
Any idea??
more code-
<div class="grid_12">
<div class="grid_6 half-c half_m2" align="center" style="border-radius:100px 0 0 100px">
<form method="post" action="classes/action.php">
<table>
<tr>
<th colspan="2"><label class="eh1 eh1m">Login as Visitor</label> </th>
</tr>
<tr>
<td><br /></td>
<td></td>
</tr>
<tr>
<td><label class="eh2">Username</label></td>
<td><input type="text" name="txtVUname" class="etxt1 etxtm1"/></td>
</tr>
<tr>
<td><label class="eh2">Password</label></td>
<td><input type="password" name="txtVPwd" class="etxt1 etxtm1"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnVLogin" value="Login" style="float: right" /></td>
</tr>
</table>
</form>
</div>
<div class="grid_6 half-c half_m2" align="center" style="border-radius:0 100px 100px 0">
<form method="post" action="classes/action.php" >
<table>
<tr>
<th colspan="2"><label class="eh1 eh1m">Login as a Company</label></th>
</tr>
<tr>
<td><br /></td>
<td></td>
</tr>
<tr>
<td><label class="eh2">Username</label></td>
<td><input type="text" name="txtCUname" class="etxt1 etxtm1"/></td>
</tr>
<tr>
<td><label class="eh2">Password</label></td>
<td><input type="password" name="txtCPwd" class="etxt1 etxtm1"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnComLogin" value="Secure Login" style="float: right" /></td>
</tr>
</table>
</form>
</div>
</div>
folder structure looks like--
mysite.com
- classes
- action.php
- login.php (containing form)
one more thing.. i can do the same from another page having form and a submit button to redirect on classes/action.php page
You can try this
<form method="post" action="./classes/action.php">
Be careful that file names are case-sensitive in unix!
very simple mistake only. Replace form action and say me the result
<form method="post" action="../mywebsitename/classes/action.php" >
change the action.php to action2.php and try
<form method="post" action="../mywebsitename/classes/action2.php" >
You should return back by .. So if your form file in the same folder contains the classes folder your code will work, if your form file in internal folder like files/form_file.PHP and the folder files in the same classes folder your code will be:
<form method="post" action="<?php echo $_SERVER['HTTP_HOST']; ?>/classes/action.php" >
And so on.

How to send image value from form to another page?

I am working on one project in which there is one form filled by user and that value displayed in another page. All data I get in another page but image can't display on that page only image name is displayed. I want to display image so how can I do this?
page1
<form action="save.php" class="contact-form" method="post" name="inputname">
<table>
<tr>
<td class="label">Name:</td>
<td><input type="text" class="input-text" name="pname" /></td>
</tr>
<tr>
<td class="label">City:</td>
<td><input type="text" class="input-text" name="pcity" /></td>
</tr>
<tr>
<td class="label">Country:</td>
<td><input type="text" class="input-text" name="pcountry" /></td>
</tr>
<tr>
<td class="label">Email:</td>
<td><input type="text" class="input-text" name="pemail" /></td>
</tr>
<tr>
<td class="label">Upload Your Photo:</td>
<td><input type="file" accept="image/jpg,image/gif" class="input-text" name="pphoto"/></td>
</tr>
page 2 save.php
mysql_connect("localhost","root","");
mysql_select_db("my_db");
$p_name=$_POST['pname'];
$p_city=$_POST['pcity'];
$p_country=$_POST['pcountry'];
$p_email=$_POST['pemail'];
$p_photo=$_POST['pphoto'];
<table>
<ul>
<tr>
<td><li class="image"><img src="<? echo $p_photo; ?>" /></li></td>
<li class="text">
<td class="label">
Name: <? echo $p_name; ?></br>
City: <? echo $p_city; ?></br>
Country: <? echo $p_country; ?></br>
E-Mail: <? echo $p_email; ?></br>
</td>
</li>
</tr>
</ul>
</table>
If you upload image as file then you should work with $_FILES array. And you should save uploaded image first.
#$file = fopen($_FILES['file'] ['tmp_name'], "r");
#$image = addslashes(fread($file, filesize($_FILES['file']['tmp_name'])));
Use your file name instead of 'file'.

Error Placing on same page PHP

some of my code in addUser.php it pure html
addUser.php
<form action="process/addNewUser.php" method="POST" id="userForm">
<table width="79%" border="0" cellspacing="6" cellpadding="1"
class="tabcont">
<tr>
<td width="47%" align="right">Title:</td>
<td width="53%">
<select name="title"><option value='0'>- - select - -</option>
</select>
</td>
</tr>
<tr>
<td width="47%" align="right">
First Name:</td>
<td width="53%"><input type="text" id="firstname" name="firstName" class="required" /></td>
</tr>
<tr>
<td align="right">Middle Name:</td>
<td><input type="text" id="middlename" name="middleName" class="name" /></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input name="password" value="" readonly="readonly"
id="password" class="required" " /></td>
</tr>
<tr>
<td align="right" colspan="2">
<input name="addNewUser" type="submit" class="submit" id="submit" value="Submit" />
</td>
</tr>
</table>
</form>
addNewUser.php
Here i am doing validations and displaying error messages and if it is success sending him to another page.
But i want to show an error message on addUser.php instead of validations page. Please give me a sample code how i can do it.
addNewUser.php
Add the message in the session
$_SESSION["ErrorMsg"]="Name already exists";
And in your addUser.php , you put the following code in the place you need to show the msg :
if($_SESSION["ErrorMsg"])
{
echo $_SESSION["ErrorMsg"];
$_SESSION["ErrorMsg"]="";
}

Why isn't Recaptcha showing up from PHP using XMLHttpRequest?

::EXPLINATION::
In an HTML file, I'm attempting to load a registration frame with a captcha check. The form itself shows up. The captcha does not. So I know that the javascript (posted below) gets what I want it to get. But there's something wrong that is keeping my captcha from showing up.
Just as a final note, I'm targetting a div with the id "splashTarget" I use CSS to arrange everything how I want it. I'm not going to post that because its probably not relevant, but if you think I do need to post it to get help let me know.
::CODE::
The form that doesn't seem to work:
<div class="splash"> </div>
<div style="text-align:left" id="registrationSplash" class="splashContent">
<div style="text-align:right">
<a style="color:darkred" href="javascript:closeSplash()">[ CANCEL ]</a>
</div>
<h1>REGISTER</h1>
<form action="" method="post" id="registerForm">
<?PHP
require_once('recaptchalib.php');
$publickey = "[censored]";
echo recaptcha_get_html($publickey);
echo '<!--'.recaptcha_get_html($publickey).'-->';
?>
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="firstname" maxlength="60"></td>
<td>Username:</td>
<td><input type="text" name="username" maxlength="30"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" maxlength="60"></td>
<td>Password:</td>
<td><input type="password" name="pass" maxlength="30"></td>
</tr>
<tr>
<td>E-mail Address:</td>
<td><input type="text" name="firstname" maxlength="60"></td>
<td>Confirm Password:</td>
<td><input type="password" name="pass2" maxlength="30"></td>
</tr>
<tr>
<th colspan=4 style="text-align:right">
<button onclick="submitFormRegisterSplash()" type="button" name="submit" value="Login">Register!</button>
</th>
</tr>
</table>
</form>
<div id="status" />
</div>
The actual call to recaptia.
<?PHP
require_once('recaptchalib.php');
$publickey = "[censored]";
echo recaptcha_get_html($publickey);
echo '<!--'.recaptcha_get_html($publickey).'-->';
?>
Javascript Function used to load Register form:
function onRegisterClicked() {
var onRegisterClickedHttp;
if(window.XMLHttpRequest) {
onRegisterClickedHttp = new XMLHttpRequest();
onRegisterClickedHttp.onreadystatechange = function() {
if(onRegisterClickedHttp.readyState==4 && onRegisterClickedHttp.status==200) {
var response = onRegisterClickedHttp.responseText;
document.getElementById("splashTarget").innerHTML = response;
}
}
}
onRegisterClickedHttp.open("GET", "Verification/RegisterSplash.php", true);
onRegisterClickedHttp.send();
}
Result on Webpage after calls to create
<div id="splashTarget">
<div class="splash"> </div>
<div style="text-align:left" id="registrationSplash" class="splashContent">
<div style="text-align:right">
<a style="color:darkred" href="javascript:closeSplash()">[ CANCEL ]</a>
</div>
<h1>REGISTER</h1>
<form action="" method="post" id="registerForm">
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LehEsgSAAAAAAH2xfKSXKSdldMwoiOqZyO5TupV"></script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=6LehEsgSAAAAAAH2xfKSXKSdldMwoiOqZyO5TupV" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript><!--<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LehEsgSAAAAAAH2xfKSXKSdldMwoiOqZyO5TupV"></script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=6LehEsgSAAAAAAH2xfKSXKSdldMwoiOqZyO5TupV" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>--> <table>
<tbody><tr>
<td>First Name:</td>
<td><input type="text" name="firstname" maxlength="60"></td>
<td>Username:</td>
<td><input type="text" name="username" maxlength="30"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" maxlength="60"></td>
<td>Password:</td>
<td><input type="password" name="pass" maxlength="30"></td>
</tr>
<tr>
<td>E-mail Address:</td>
<td><input type="text" name="firstname" maxlength="60"></td>
<td>Confirm Password:</td>
<td><input type="password" name="pass2" maxlength="30"></td>
</tr>
<tr>
<th colspan="4" style="text-align:right">
<button onclick="submitFormRegisterSplash()" type="button" name="submit" value="Login">Register!</button>
</th>
</tr>
</tbody></table>
</form>
<div id="status">
</div>
</div></div>
The Website in action is gumonshoe dot net slash Registration
You'll need to choose to try to register to see the pop up. I disabled the CSS that created the splash screen thinking that it might have been an issue with z-indexes. That doesn't appear to be the case.
Thanks for any tips.
The form HTML DOES work (see http://jsfiddle.net/5p5K3/). The error is caused by a feature:
<script> tags which are injected using .innerHTML = .... <script> are not parsed (functions and variables inside these tags are not defined, nor called). You have to include the CAPTCHA code inside the page, instead of adding it using AJAX.
EDIT
Add this HTML code (inside the <head> block):
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
Overwrite your function by my suggestion (replace <PUBLIC kEY HERE> by your public key):
function onRegisterClicked() {
Recaptcha.create("<PUBLIC KEY HERE>", "splashTarget", {
theme: "red",
callback: Recaptcha.focus_response_field
});
}
Obvious problem: The inserted recaptcha code is commented out with <!-- -->. Commented-out html/js is NOT going to be rendered/executed. Change
echo '<!--'.recaptcha_get_html($publickey).'-->';
to
echo recaptcha_get_html($publickey);

Categories