forms - Transfer value to other page using PHP session - textarea -


transfer value page successful, have read many topics on subject, stockoverflow helped me this.

on first page (eg page1.php) have input. type value it.

with php write in session variable , after clicking submit can transfer value other side (eg page2.php) simple contact page. value pasted textarea field.

my problem takes value type directly input, located in page1.php. wanted create rather calculator, consist of price according entered number of kilograms of product. (the kilogram value entered in input).

how form field clean, , order product redirected correctly?

my code in page1.php :

<?php session_start(); $_session['towar1'] = $cena1; ?>  <form method="get" action="kontakt.php"> <input id="wart1" type="number" value="0" name="towar1" class="ilosc" required> </form> 

my code in page2.php(conttact page) :

<?php session_start(); $cena1 = $_get['towar1']; ?>  <label for="wiadomosc"></label> <textarea placeholder="" name="wiadomosc" required><?php echo $cena1 ?></textarea> 

///problem

when trying figure how value of product price (e.g. 1 kg 19$) wrote code of kind directly on page2.php:

<?php echo $cena1*19 ?> 

but when this, direct entrance on contact page gives me written text 0 (zero).

can avoid 0? how can make textarea blank always, , page1.php (calculator) calculate correct number (const 19$ per kilo , number of kilos entered in input)

your question quite not clear, lets go through this: page1.php contains input manage item quantity , $_session variable price, on page 2 need display quantity*price_per_item number, right? if yes, try following approach:

<?php session_start(); $cena1 = $_get['towar1'] * $_session['towar1']; ?>  <label for="wiadomosc"></label> <textarea placeholder="" name="wiadomosc" required><?php echo $cena1 ?></textarea> 

, $_get['towar1'] items quantity , $_session['towar1'] item price.

p.s more adnvanced technique not hesitate ask in comments.

hope helps, cheers.

edit

considering our converstation in comments can assume approach helps you:

$cena1 = (!empty($_get['towar1']) && $_get['towar1'] != 0 )? $_get['towar1'] * 19 : '';

this line check if $_get['towar1'] variable not empty , not zero. if match condition - make calculation, else - return empty string (not zero).

please note we're talking above not secure , can abused end-user. please consider review input validation aproach.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -