Preserve form values from page to page - php

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;
}?>

Related

PHP variable add another page

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>

Trying to multiply two user inputs PHP

I'm trying to make a movie theatre webpage. Very nooby, with almost no PHP and HTML experience. We are learning in school, and we are just using Adobe Dreamweaver to insert stuff like recordsets, bindings, tables etc.
Now I want to make the page where the user can order a ticket, I've created a form, however it only inserts the value of one ticket(obv). I want to make the price to show for 1 ticket, but be stored in MySQL database as price*amount of tickets. I'd be very happy if someone could help me out here:
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Pris_kr:</td>
<td><?php echo $row_Recordset1['pris_kr']; ?> pr billett<input type="hidden" value="<?php $row_Recordset1['pris_kr']*$row_antall_billetter;?>"/></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Personid:</td>
<td><select name="personid">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['personid']?>" ><?php echo $row_Recordset1['epost']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Antall_billetter:</td>
<td><input type="text" name="antall_billetter" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Rad:</td>
<td><input type="text" name="rad" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sete:</td>
<td><input type="text" name="sete" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="bestillingsid" value="" />
<input type="hidden" name="visningsid" value="<?php echo $_GET['visningsid']; ?>" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
again, I'm a newbe and I'm aware of the fault in the code:
<td nowrap="nowrap" align="right">Pris_kr:</td>
<td><?php echo $row_Recordset1['pris_kr']; ?> pr billett<input type="hidden" value="<?php $row_Recordset1['pris_kr']*$row_antall_billetter;?>"/></td>
Am I heading towards something that could help me though?
I'm also using two views here, to get the right time and date, so the url parameters here are "visningsid" and "bestillingsid".
Some translations:
Pris_kr=Price in kr, Antall_billetter=Amount of tickets
The others are not very important I guess.
Thanks in advance
//Sander

Insert a form in a jquery tab to submit data in database using php

I am using a form to submit data in three different tables, it is actually is a simple form with one submit button.
But now I want the form to be divided in three different tabs each having a button, when the page is loaded first tab should be opened with a form having personal details with a proceed button on clicking proceed button second tab should open up containing another part of form and same goes to final tab having a submit button.
I am not getting it how can it be done with php and JQuery tab.
this was the code i wrote
<script type="text/javascript">
function OtherWork(val){
var element=document.getElementById('wtype');
if(val=='other')
element.style.display='block';
else
element.style.display='none';
}
</script>
<h2>Add New Entry</h2>
<hr />
<form action="processnewentry.php" method="post" name="myForm" onsubmit="return validateForm();" >
<table width="560" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="234">Lead Name :</td>
<td width="311"><input type="text" name="lename" /></td>
</tr>
<tr>
<td width="234">Lead Date : (mm/dd/yyyy)</td>
<td width="311"><input type="text" name="ldate" class="datepicker" /></td>
</tr>
<tr>
<td width="234">Contact Person :</td>
<td width="311"><input type="text" name="conper" /></td>
</tr>
<tr>
<td width="234">Company Name :</td>
<td width="311"><input type="text" name="cname" /></td>
</tr>
<tr>
<td width="234">Mobile No. :</td>
<td width="311"><input type="text" name="mobno" /></td>
</tr>
<tr>
<td width="234">Landline No. :</td>
<td width="311"><input type="text" name="phone" /></td>
</tr>
<tr>
<td width="234">Address :</td>
<td width="311"><textarea name="address" ></textarea></td>
</tr>
<tr>
<td width="234">Email :</td>
<td width="311"><input type="text" name="email" /></td>
</tr>
<tr>
<td width="234">Alt Address :</td>
<td width="311"><textarea name="altaddress" ></textarea></td>
</tr>
<tr>
<td width="234">Work Type :</td>
<td width="311"><select name="wtype" onchange='OtherWork(this.value);'>
<option value="Website Designing">Website Designing</option>
<option value="Android Application">Android Application</option>
<option value="other">Other</option>
</select><br />
<input type="text" name="wtype" id="wtype" style='display:none;'/>
</td>
</select>
</tr>
<tr>
<td width="234">Work Description :</td>
<td width="311"><textarea name="wdesc" ></textarea></td>
</tr>
<tr>
<td width="234">Expected Budget :</td>
<td width="311"><input type="text" name="exbudget" /></td>
</tr>
<tr>
<td width="234">Lead Executive :</td>
<td width="311"><select name="lexec">
<?php
$q=mysql_query('SELECT * FROM $table');
while($rr=mysql_fetch_array($q))
{
$na=$rr['name'];
?>
<option value="<?php echo $na;?>"><?php echo strtoupper($na);?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td width="234">Lead Manager :</td>
<td width="311"><select name="lmana">
<?php
$q=mysql_query('SELECT * FROM $table');
while($rr=mysql_fetch_array($q))
{
$na=$rr['name'];
?>
<option value="<?php echo $na;?>"><?php echo strtoupper($na);?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td width="234">Closing Date : (mm/dd/yyyy)</td>
<td width="311"><input type="text" name="cldate" class="datepicker" /></td>
</tr>
<tr>
<td width="234">Lead Status :</td>
<td width="311"><select name="lstat">
<option value="Hot">Hot</option>
<option value="Warm">Warm</option>
<option value="Cold">Cold</option>
</select></td>
</tr>
<tr>
<td width="234">Follow Up :</td>
<td width="311"><textarea name="followup" ></textarea></td>
</tr>
<tr>
<td width="234">Next Follow up : (mm/dd/yyyy)</td>
<td width="311"><input type="text" name="nfoldate" class="datepicker" /></td>
</tr>
<tr>
<td width="234">Remark if any :</td>
<td width="311"><textarea name="remark" ></textarea></td>
</tr>
<tr>
<td width="234"> </td>
<td width="311"><input name="submit" type="submit" value="Submit" class="buttton" /></td>
</tr>
</table>
</form>
your form is having 3 parts(i.ir 3 different tabs).So give 3 different html classes to its fields.Eg.
fields on first tab will look like :
fields on first tab will look like :
fields on first tab will look like :
At first, fields on second and third tab would be display none.
Now on click of first proceed button, validate fields(if required) and then, make fields on first tab display none using jquery(i.e. add css property)
Eg.
$("#first_proceed").click(function(){
$(".first").css("display","none");
})
Same for second proceed button.
And on click of third button(i.e. submit), Submit your form

storing the values into the cookie and displaying those values on page load

hi i have an php form which contains many fields, now i tried to write the code for storing all those values into an array and store them in a cookie in javascript. the code is as follows :
<script type="text/javascript">
function setDate()
{
var today = new Date();
var month = today.getMonth() + 1;
var day = today.getDate();
var year = today.getFullYear();
document.forms['form1'].elements['date'].value= month + "/" + day + "/" + year;
}
function add_newoption(optionname)
{
document.getElementById(optionname).InnerHTML = "";
}
var win = null;
function optionWindow(mypage,myname,w,h){
LeftPosition = (screen.width) ? (screen.width-w)/2: 0;
TopPosition = (screen.height) ? (screen.height-h)/2: 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
win = window.open(mypage,myname,settings);
win.focus();
}
function setAction(act)
{
document.forms['form1'].action = act;
document.forms['form1'].submit();
}
</script>
and the code for the form is as follows:
<body onLoad="setDate();">
<br/>
<center>
<fieldset class="style1" style="width:800px; background-color:#FFFFFF">
<h4 align="center"> Designer Form </h4>
<form id="form1" name="form1" method="post" >
<table width="700" border="0" cellpadding="2" cellspacing="2" bgcolor="#FFFFFF" style="text-align:left; padding: 25px 0px 25px 0px;">
<tr>
<td width="174" align="right">Date:</td>
<td width="331"><input name="date" type="text" size="10" readonly/></td>
<td width="175" style="text-align:center;">Order Number:
<input name="order_num" type="text" size="10" value=""/></td>
</tr>
<tr>
<td > </td>
<td> </td>
<td style="text-align:center;"><input name="orderdetails" type="submit" value="Get Order Details" onClick="setAction('?action=getorder');"/></td>
</tr>
<tr>
<td colspan='4'> <input name="email" id="email" type="hidden" value=""/> </td>
</tr>
<tr>
<td align="right">First Name:</td>
<td><input name="fname" type="text" value=""/></td>
<td> </td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td><input name="lname" type="text" value=""/></td>
<td> </td>
</tr>
<tr>
<td align="right">Image Submitted:</td>
<td><input name="image" type="text" /></td>
<td> </td>
</tr>
<tr>
<td align="right">General Comments: </td>
<td><textarea name="gen_comments" cols="50" rows="6"></textarea></td>
<td> </td>
</tr>
<tr>
<td align="right">Internal Comments:</td>
<td><textarea name="int_comments" cols="50" rows="6"></textarea></td>
<td> </td>
</tr>
<tr>
<td align="right">Quality of the File:</td>
<td colspan="2" style="padding-right:4px">
<select name="quality">
<option>Select One</option><option value="good">Good</option><option value="ok">A bit low but we can use it</option><option value="low">Low. We are concerned it might effect the qaulity of the final</option><option value="not good">Not good. We cannot work with it</option><option value="test2">test2</option><option value="test">test</option><option value="lisa">Lisa1</option><option value="bbb">aaa</option> <!--option value="good">Good</option>
<option value="ok">A bit low but we can use it</option>
<option value="low">Low. We are concerned it might effect the qaulity of the final </option>
<option value="not good">Not good. We can't work with it</option-->
</select>
now what i want to do here is to get all these values entered in the form to store into an array and have to set cookie to retrieve them when the page re-loads...
how can i write a function for that using javascript and where to call that function in the form for getting those values into the form on page reloads..??
Any help will be needful to me....thanks in advance..
well i think you should use localStorage.setItem("DataKey","DataValue"); for store any value.
and for getting value you can use localStorage.getItem("DataKey");
FF,chrome,safari are support localStorage but i dont know about IE.

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"]="";
}

Categories