Print foreach inside an html script on php file - php

I'm having a big problem.
I have this code and I want to print that values in other page.
FORM
<p>
<input type="hidden" value="" name="reconhecimento_sabado" checked>
<input type="checkbox" value="Sábado, 4 de Março de 2017<br>" name="reconhecimento[]" onclick="chkChecks('reconhecimento[]')"> Sábado, 4 de Março de 2017
</p>
<p>
<input type="hidden" value="" name="reconhecimento_domingo" checked>
<input type="checkbox" value="Domingo, 5 de Março de 2017<br>" name="reconhecimento[]" onclick="chkChecks('reconhecimento[]')"> Domingo, 5 de Março de 2017
</p>
<p>
<input type="hidden" value="" name="reconhecimento_quinta" checked>
<input type="checkbox" value="Quinta-feira, 9 de Março de 2017<br>" name="reconhecimento[]" onclick="chkChecks('reconhecimento[]')"> Quinta-feira, 9 de Março de 2017
</p>
<p>
<input type="hidden" value="" name="reconhecimento_sexta" checked>
<input type="checkbox" value="Sexta-feira, 10 de Março de 2017<br>" name="reconhecimento[]" onclick="chkChecks('reconhecimento[]')"> Sexta-feira, 10 de Março de 2017
</p>
And here I have the code from the other page, like this I can print my values form the previously page.
$reconhecimento = $_POST['reconhecimentos'];
foreach ($reconhecimento as $reconhecimento=>$value) {
echo $value;
}
$html="TESTE de codigo FIM DO TESTE";
echo $html;
But like this I can't, help me please.
$reconhecimento = $_POST['reconhecimentos'];
$html="TESTE de codigo ".foreach ($reconhecimento as $reconhecimento=>$value) { echo $value; }." FIM DO TESTE";
echo $html;

Ensure you aren't self-referencing the array you are looping over:
foreach ($reconhecimento as $r=>$value) { echo $value; }
Also, Don't assign your foreach inside a string. Do this:
echo "TESTE de codigo: ";
foreach ($reconhecimento as $r = >$value) {
echo $value;
}
echo $html;

Related

Update Mysql DB from checkboxes

I am trying to give the values ​​0 or 1 to the fields of a database depending on whether the checkbox is checked or not,
but i can't find it and i can't find where is my problem, can you help me?
<?php
//connexion à la base de donnée
include_once "../connexion.php";
//on récupère le id dans le lien
$id = $_GET['id'];
//requête pour afficher les infos d'un employé
$req = mysqli_query($con , "SELECT * FROM lecteur_badge_statique WHERE id = $id");
$row = mysqli_fetch_assoc($req);
//vérifier que le bouton modifier a bien été cliqué
if(isset($_POST['button'])){
//extraction des informations envoyé dans des variables par la methode POST
extract($_POST);
//verifier que tous les champs ont été remplis
if(isset($lb1) && $lb2){
//requête de modification
$req = mysqli_query($con, "UPDATE lecteur_badge_statique SET lb1 = '$lb1' , lb2 = '$lb2' , lb3 = '$lb3, lb4 = '$lb4, lb5 = '$lb5, lb6 = '$lb6, lb7 = '$lb7, lb8 = '$lb8, lb9 = '$lb9, lb10= '$lb10'
lb11 = '$lb11' , lb12 = '$lb12' , lb13 = '$lb13, lb14 = '$lb14, lb15 = '$lb15, lb16 = '$lb16, lb17 = '$lb17, lb18 = '$lb18, lb19 = '$lb19, lb20= '$lb20'
lb21 = '$lb21' , lb22 = '$lb22' , lb23 = '$lb23, lb24 = '$lb24, lb25 = '$lb25, lb26 = '$lb26, lb27 = '$lb27, lb28 = '$lb28, lb29 = '$lb29, lb30= '$lb30'
lb31 = '$lb31' , lb32 = '$lb32' , lb33 = '$lb33, lb34 = '$lb34, lb35 = '$lb35, lb36 = '$lb36, lb37 = '$lb37, lb38 = '$lb38, lb39 = '$lb39, lb40= '$lb40'
lb41 = '$lb41' , lb42 = '$lb42' , lb43 = '$lb43, lb44 = '$lb44, lb45 = '$lb45, lb46 = '$lb46, lb47 = '$lb47, lb48 = '$lb48, lb49 = '$lb49, lb50= '$lb50'
WHERE id = $id");
$error_message = mysqli_error($con);
if($error_message == ""){
echo "No error related to SQL query.";
}else{
echo "Query Failed: ".$error_message;
}
if($req){//si la requête a été effectuée avec succès , on fait une redirection
header("location: index.php");
}else {//si non
$message = "Employé non modifié";
}
}else {
//si non
$message = "Veuillez remplir tous les champs !";
}
}
?>
<div class="form">
<img src="images/back.png"> Retour
<h2>Modifier l'employé : <?=$row['nom']?> </h2>
<p class="erreur_message">
<?php
if(isset($message)){
echo $message ;
}
?>
</p>
<form action="" method="POST">
<label>lb1</label>
<input type="checkbox" name="lb1" value="<?=$row['lb1']?>">
<label>lb2</label>
<input type="checkbox" name="lb2" value="<?=$row['lb2']?>">
<label>lb3</label>
<input type="checkbox" name="lb3" value="<?=$row['lb3']?>">
<label>lb4</label>
<input type="checkbox" name="lb4" value="<?=$row['lb4']?>">
<label>lb5</label>
<input type="checkbox" name="lb5" value="<?=$row['lb5']?>">
<label>lb6</label>
<input type="checkbox" name="lb6" value="<?=$row['lb6']?>">
<label>lb7</label>
<input type="checkbox" name="lb7" value="<?=$row['lb7']?>">
<label>lb8</label>
<input type="checkbox" name="lb8" value="<?=$row['lb8']?>">
<label>lb9</label>
<input type="checkbox" name="lb9" value="<?=$row['lb9']?>">
<label>lb10</label>
<input type="checkbox" name="lb10" value="<?=$row['lb10']?>">
<label>lb11</label>
<input type="checkbox" name="lb11" value="<?=$row['lb11']?>">
<label>lb12</label>
<input type="checkbox" name="lb12" value="<?=$row['lb12']?>">
<label>lb13</label>
<input type="checkbox" name="lb13" value="<?=$row['lb13']?>">
<label>lb14</label>
<input type="checkbox" name="lb14" value="<?=$row['lb14']?>">
<label>lb15</label>
<input type="checkbox" name="lb15" value="<?=$row['lb15']?>">
<label>lb16</label>
<input type="checkbox" name="lb16" value="<?=$row['lb16']?>">
<label>lb17</label>
<input type="checkbox" name="lb17" value="<?=$row['lb17']?>">
<label>lb18</label>
<input type="checkbox" name="lb18" value="<?=$row['lb18']?>">
<label>lb19</label>
<input type="checkbox" name="lb19" value="<?=$row['lb19']?>">
<label>lb20</label>
<input type="checkbox" name="lb20" value="<?=$row['lb20']?>">
<label>lb21</label>
<input type="checkbox" name="lb21" value="<?=$row['lb21']?>">
<label>lb22</label>
<input type="checkbox" name="lb22" value="<?=$row['lb22']?>">
<label>lb23</label>
<input type="checkbox" name="lb23" value="<?=$row['lb23']?>">
<label>lb24</label>
<input type="checkbox" name="lb24" value="<?=$row['lb24']?>">
<label>lb25</label>
<input type="checkbox" name="lb25" value="<?=$row['lb25']?>">
<label>lb26</label>
<input type="checkbox" name="lb26" value="<?=$row['lb26']?>">
<label>lb27</label>
<input type="checkbox" name="lb27" value="<?=$row['lb27']?>">
<label>lb28</label>
<input type="checkbox" name="lb28" value="<?=$row['lb28']?>">
<label>lb29</label>
<input type="checkbox" name="lb29" value="<?=$row['lb29']?>">
<label>lb30</label>
<input type="checkbox" name="lb30" value="<?=$row['lb30']?>">
<label>lb31</label>
<input type="checkbox" name="lb31" value="<?=$row['lb31']?>">
<label>lb32</label>
<input type="checkbox" name="lb32" value="<?=$row['lb32']?>">
<label>lb33</label>
<input type="checkbox" name="lb33" value="<?=$row['lb33']?>">
<label>lb34</label>
<input type="checkbox" name="lb34" value="<?=$row['lb34']?>">
<label>lb35</label>
<input type="checkbox" name="lb35" value="<?=$row['lb35']?>">
<label>lb36</label>
<input type="checkbox" name="lb36" value="<?=$row['lb36']?>">
<label>lb37</label>
<input type="checkbox" name="lb37" value="<?=$row['lb37']?>">
<label>lb38</label>
<input type="checkbox" name="lb38" value="<?=$row['lb38']?>">
<label>lb39</label>
<input type="checkbox" name="lb39" value="<?=$row['lb39']?>">
<label>lb40</label>
<input type="checkbox" name="lb40" value="<?=$row['lb40']?>">
<label>lb41</label>
<input type="checkbox" name="lb41" value="<?=$row['lb41']?>">
<label>lb42</label>
<input type="checkbox" name="lb42" value="<?=$row['lb42']?>">
<label>lb43</label>
<input type="checkbox" name="lb43" value="<?=$row['lb43']?>">
<label>lb44</label>
<input type="checkbox" name="lb44" value="<?=$row['lb44']?>">
<label>lb45</label>
<input type="checkbox" name="lb45" value="<?=$row['lb45']?>">
<label>lb46</label>
<input type="checkbox" name="lb46" value="<?=$row['lb46']?>">
<label>lb47</label>
<input type="checkbox" name="lb47" value="<?=$row['lb47']?>">
<label>lb48</label>
<input type="checkbox" name="lb48" value="<?=$row['lb48']?>">
<label>lb49</label>
<input type="checkbox" name="lb49" value="<?=$row['lb49']?>">
<label>lb50</label>
<input type="checkbox" name="lb50" value="<?=$row['lb50']?>">
<input type="submit" value="Modifier" name="button">
</form>
</div>
I would like that when the page loads, the database fields that contain the value 1 are checked and then we can check/uncheck the boxes that we want to update to 1 or 0 in the DB.
But already when loading the page the boxes are not checked when they are 1 in the DB.
value="<?=$row['']?> with checkbox doesn't work the same as input type text?
Thanks in advance for your help :)
If a checkbox is checked it will have the checked attribute:
<input type="checkbox" name="agree" value="1" checked />
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/checkbox
You can set your checkbox as checked by checking if the value is set in PHP like so:
<input type="checkbox" name="agree" value="1" <?= $row['xyz'] ? 'checked' : null ?> />
As an aside, you should take note of what Dharman said in the comments regarding MySQL injection, I would recommend using PDO and prepared statements, have a quick read through this, it is very helpful https://phpdelusions.net/pdo

Update Mysql with form

I would like to update a sql table with a html form. I would like to select the element with a drop-down list and later update the values with the form.
Here is my code, the drop-down list and the form works, but I didn't know how to make that the php code get the element that I select.
HTML form:
<?php
require("conectarBD.php");
$select = "SELECT id_serie, nombre FROM series";
$result = $conectar->query($select);
?>
Selecciona la serie que quieres modificar:
<br>
<select>
<?php
while ( $row = $result->fetch_array() )
{
?>
<option value=" <?php echo $row['id_serie'] ?> " >
<?php echo $row['nombre']; ?>
</option>
<?php
}
?>
</select>
<form action="modificar_serie.php" method="post">
<p>
Introduce los cambios a realizar:
</p>
<p>
<label for="textfield">Nombre</label>
<input type="text" name="nom" id="nom" />
<label for="textarea"></label>
</p>
<p>
<label for="textfield">Temporadas</label>
<input type="number" name="temp" id="temp" />
<label for="textarea"></label>
</p>
<p>
<label for="textfield"> Año de estreno</label>
<input type="text" name="est" id="est" />
<label for="textarea"></label>
</p>
<input type="Submit" value="Actualizar">
</form>
PHP:
<?php
require("conectarBD.php");
$nombre = $_POST["nombre"];
$temp = $_POST["temp"];
$est = $_POST["est"];
$query="UPDATE series SET nombre = '.$nombre.', temporadas = '.$temp.', estreno= '.$est.' WHERE nombre='$nombre'";
mysqli_query($conectar,$query);
if(mysqli_affected_rows()>=0){
echo "<p>($nombre) Datos Actualizados<p>";
}else{
echo "<p>($nombre) No se ha podido actualizar en estos momentos<p>";
}
header("Location: ../index.php");
?>
Your select element must be inside form and have a name. Then you will be able to get a value of it from $_POST.

Can 2 $_POST conflict with eachother?

So I am trying to use the intel I got on the first $_POST on the second $_POST but when the second occurs the intel from the first is lost, what can I do to overcome this?
<?php
if(isset($_POST['entrar'])) {
$nr_processo = $_POST['nr_processo'];
echo "$nr_processo";
$aluno = mysql_query("SELECT * FROM alunos WHERE nr_processo = '$nr_processo'");
$row = mysql_fetch_array($aluno) or die ("Este numero de processo não está registado " . mysql_error()) ;
$aluno_nome = $row['nome'];
$aluno_ano = $row['ano'];
$aluno_turma = $row['turma'];
$aluno_ciclo = $row['ciclo'];
echo $aluno_nome, $aluno_ano, $aluno_turma, $aluno_ciclo;
}
?>
<form method="post" action="">
<label> A que se deve a tua visita ah biblitoeca?</label><br>
<label> Estudo/pesquisa</label>
<input name="estudo" value="1" type="checkbox">
<br>
<label> Leitura Periódica</label>
<input name="leitura" value="1" type="checkbox">
<br>
<label>Internet</label>
<input name="net" value="1" type="checkbox">
<br>
<label> Audiovisuais</label>
<input name="audiovisuais" value="1" type="checkbox"> <br>
<input name="enviar" value="Enviar" type="submit">
</form>
<?php
if(isset($_POST['enviar'])) {
$estudo = $_POST['estudo'];
$leitura = $_POST['leitura'];
$internet = $_POST['net'];
$audiovisuais = $_POST['audiovisuais'];
echo $aluno_nome;
$data = date('Y-m-d ');
$hora = date('H:i:s');
echo $data, $hora;
mysql_query("INSERT INTO entradas VALUES('', '$nr_processo', '$aluno_ano', '$aluno_turma', '$estudo', '$leitura', '$internet', '$audiovisuais', '$data', '$hora' )") ;
?>
<!-- <META http-equiv="refresh" content="0;URL=http://localhost/registosbib/agradecimento.php"> -->
<?php
}
?>
You post entrar and enviar in the same request or 2 different requests ?
Edit:
The 2 $_POST doesn't conflict
Fix:
Use $_SESSION instead
session_start();
$_SESSION['row'] = $row;
Then in the second $_POST use $_SESSION['row']['nome'] instead of $aluno_nome and other $aluno_* variables

can´t update my database

So, I'm getting an id_cliente from another php and I get it correctly from that id. I want to update my database but I can't find a way to do it. I've tried UPDATE, a friend of mine checked the code for syntax error, but I still want to see if any of use were wrong.
Here's my body:
<body>
<div class="maindiv">
<div class="form_div">
<div class="title">
<h2>Insertando datos a la tabla de Cliente.</h2>
</div>
<?php
$id_cliente = $_POST['id_cliente'];
?>
<form action="actualizar.php" method="post">
<?php
$query= "SELECT * FROM cliente WHERE $id_cliente = id_cliente";
include "../conexion/conexion.php";
$sql = mysqli_query($conn, $query);
if(empty($sql)) echo "No se encontró ningún personal que coincida con la búsqueda";
else{
while($row = mysqli_fetch_object($sql)){ ?>
<h2>Llena todos los campos.</h2>
<label>Clave:</label>
<input class="input" name="clave" type="number" value="<?php echo $row->CLAVE ?>">
<label>Nombre:</label>
<input class="input" name="nombre" type="text" value="<?php echo $row->NOMBRE ?>">
<label>Apellido Paterno:</label>
<input class="input" name="apellido_p" type="text" value="<?php echo $row->APELLIDO_P ?>">
<label>Apellido Materno:</label>
<input class="input" name="apellido_m" type="text" value="<?php echo $row->APELLIDO_M ?>">
<label>Direccion:</label>
<textarea cols="25" name="direccion" rows="5"><?php echo $row->DIRECCION ?></textarea><br>
<label>Telefono:</label>
<input class="input" name="telefono" type="text" value="<?php echo $row->TELEFONO ?>">
<label>Correo:</label>
<input class="input" name="correo" type="text" value="<?php echo $row->CORREO ?>">
<label>Fecha de Nacimiento (AA/MM/DD):</label>
<input class="input" name="fecha" type="date" value="<?php echo $row->NACIMIENTO ?>">
<label>Saldo:</label>
<input class="input" name="saldo" type="number" value="<?php echo $row->SALDO ?>">
<?php } $conn->close(); } ?>
<?php
$connection = mysqli_connect("localhost", "root", "");
$db = mysqli_select_db($connection,"cajadeahorros");
error_reporting(0);
if(isset($_POST['submit']))
{
if($_POST['id_cliente'] == "") $_POST['id_cliente'] = "NULL";
$clave = $_POST['clave'];
$nombre = $_POST['nombre'];
$apellido_p = $_POST['apellido_p'];
$apellido_m = $_POST['apellido_m'];
$direccion = $_POST['direccion'];
$telefono = $_POST['telefono'];
$correo = $_POST['correo'];
$fecha = $_POST['fecha'];
$saldo = $_POST['saldo'];
$q="select count(1) from cliente where clave='$clave'";
$r=mysqli_query($connection,$q);
$row=mysqli_fetch_row($r);
if($row[0]>=1)
{
$x = 1;
}
else
{
$x = 0;
}
if($clave !=''&&$nombre !=''&&$apellido_p !=''&&$apellido_m !=''&&$direccion !=''&&$telefono !=''&&$correo !=''&&$fecha !=''&&$saldo !=''&&$x==0)
{
$query = mysqli_query($connection, "update cliente set clave = 'a', nombre = 'a', apellido_p='a', apellido_m='a', direccion ='a', correo='a', nacimiento='a', saldo='a' where id_cliente = '$id_cliente'");
echo "<br/><br/><span>Datos ingresados correctamente.</span>";
}
else
{
echo "<p>No se pudo insertar. <br/> Algunos campos estan vacios o la clave ya existe.</p>";
}
}
mysqli_close($connection);
?>
<input class="submit" name="submit" type="submit" value="Insertar">
</form>
</div>
</div>
</body>
Please change the top select query which you have given like
$query= "SELECT * FROM cliente WHERE $id_cliente = id_cliente";
to
$query= "SELECT * FROM cliente WHERE id_cliente = $id_cliente";

getting form inputs values and passing to php variables

I'm configurating a tpv implemented in php.
This is the file which tpv commerce gave to me:
form.php
<?PHP
// If form is submitted with all required data then show the form
// else show error page
empty($Formulario) ?
ShowForm($Ds_Merchant_Amount,$Ds_Merchant_Currency,$prod) :
ShowError();
exit;
?>
<?PHP
function ShowError () {
echo "<table width=100% height=50%><tr><td><p><h2><center>Compruebe que todos los datos del formulario son correctos!!</center></h2></p></td></tr></table>\n";
} # End of function ShowError
function ShowForm ($amount,$currency,$producto) {
// Posted data
global $_POST;
// Valores constantes del comercio
$url_tpvv='xxxxxxxxxxxx';
$clave='xxxxxxxxxx';
$name='Panel piedra';
$code='xxxxxxxxxxxxxxx';
$terminal='1';
$order=date('ymdHis');
$amount = '50'; //importe
$currency='978';
$transactionType='0';
$urlMerchant=''; //ruta a fichero que notifica por email
$producto = 'Zapatos';
//$producto = '<script>'$('#requiredinput1').val()'</script>'; //nºfactura y producto
// Now, print the HTML script
echo "
<script language=JavaScript>
function calc() {
$('#Ds_Merchant_Amount').val( $('#requiredinput2').val() );
$('#Ds_Merchant_Producto').val( $('#requiredinput1').val() );
if($('#requiredinput1').val()==''){
alert('Es necesario introducir nºfactura y concepto');
return;
}
else if($('#requiredinput2').val()==''){
alert('Es necesario introducir el importe de la factura');
return;
}
else if($('#requiredinput3').val()==''){
alert('Es necesario introducir el email');
return;
}
vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms[0].submit();}
</script>
<body bgcolor=white>
<form name=compra action=$url_tpvv method=post target=tpv>
<pre>
<table>
<tr><td>";
echo "</td>
</tr><tr><td>
<input type='text' name='requiredinput1' id='requiredinput1' placeholder='Introduzca nºfactura y concepto' style='width: 250px;height: 30px;'/><br>
<input type='text' name='requiredinput2' id='requiredinput2' placeholder='Introduzca el importe de la factura' style='width: 250px;height: 30px;margin-top: 1em;'/> <br>
<input type='text' name='requiredinput3' id='requiredinput3' placeholder='Introduzca email' style='width: 250px;height: 30px;margin-top: 1em;margin-bottom: 1em;'/> <br>
<input type='hidden' name='Ds_Merchant_Amount' value='$amount' />
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Currency value='$currency'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Producto value='$producto'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Order value='$order'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_MerchantCode value='$code'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Terminal value='$terminal'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_TransactionType value='$transactionType'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_MerchantURL value='$urlMerchant'>
</td></tr><tr><td>";
// Compute hash to sign form data
// $signature=sha1_hex($amount,$order,$code,$currency,$clave);
$message = $amount.$order.$code.$currency.$transactionType.$urlMerchant.$clave;
$signature = strtoupper(sha1($message));
echo "<input type=hidden name=Ds_Merchant_MerchantSignature value='$signature'>
</td></tr>
</table>
<center><a href='javascript:calc()' class='realizarpago'>Realizar pago</a></center>
</pre>
</form>
";
} # End of function ShowForm
?>
Observe, for example, the amount. It's a variable, with a constant value, but I need to assign it the value introduced by the user.
Could you help me, please?
Thanks, Daniel
You have access to the submitted form values via the $_POST superglobal.
For example, if your form field is named amount, you can access the value using $_POST['amount']. That's the value you can assign to the $amount variable in your script.
You don't need the global $_POST; line.
Reference: http://php.net/manual/en/reserved.variables.post.php
EDIT: When you deal with form input, do not forget to sanitize it.
I finally solved it.
I had to move input visible fields (which the user has to populate) to another firstly form.
firstform.php
<form action="tpv.php" method="POST">
<input type='text' name='requiredinput1' id='requiredinput1' placeholder='Introduzca nºfactura y concepto' style='width: 250px;height: 30px;'/><br>
<input type='text' name='requiredinput2' id='requiredinput2' placeholder='Introduzca el importe de la factura' style='width: 250px;height: 30px;margin-top: 1em;'/> <br>
<input type='text' name='requiredinput3' id='requiredinput3' placeholder='Introduzca email' style='width: 250px;height: 30px;margin-top: 1em;margin-bottom: 1em;'/> <br>
<input type="submit" value="Realizar pago" />
</form>
This is the first, in which I populate three data (description , amount, email) , and send them to tpv.php . So, in tpv.php , I pick up them by using $_POST
tpv.php
<?PHP
// If form is submitted with all required data then show the form
// else show error page
empty($Formulario) ?
ShowForm($Ds_Merchant_Amount,$Ds_Merchant_Currency,$prod) :
ShowError();
exit;
?>
<?PHP
function ShowError () {
echo "<table width=100% height=50%><tr><td><p><h2><center>Compruebe que todos los datos del formulario son correctos!!</center></h2></p></td></tr></table>\n";
} # End of function ShowError
function ShowForm ($amount,$currency,$producto) {
// Posted data
global $_POST;
// Valores constantes del comercio
$url_tpvv='xxxx';
$clave='xxxx';
$name='Panel piedra';
$code='xxxx';
$terminal='1';
$order=date('ymdHis');
$amount = $_POST['requiredinput2']; //importe
$currency='978';
$transactionType='0';
$urlMerchant=''; //ruta a fichero que notifica por email
$producto = $_POST['requiredinput1'];
// Now, print the HTML script
echo "
<body bgcolor=white>
<form name=compra action=$url_tpvv method=post target=tpv>
<pre>
<table>
<tr><td>";
echo "</td>
</tr><tr><td>
<input type='hidden' name='Ds_Merchant_Amount' value='$amount' />
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Currency value='$currency'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Producto value='$producto'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Order value='$order'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_MerchantCode value='$code'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_Terminal value='$terminal'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_TransactionType value='$transactionType'>
</td></tr><tr><td>
<input type=hidden name=Ds_Merchant_MerchantURL value='$urlMerchant'>
</td></tr><tr><td>";
// Compute hash to sign form data
// $signature=sha1_hex($amount,$order,$code,$currency,$clave);
$message = $amount.$order.$code.$currency.$transactionType.$urlMerchant.$clave;
$signature = strtoupper(sha1($message));
echo "<input type=hidden name=Ds_Merchant_MerchantSignature value='$signature'>
</td></tr>
</table>
</pre>
</form>
<script language=JavaScript>
vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms[0].submit();
</script>
";
} # End of function ShowForm
?>
I hope that this answer helps others users.
Regards.

Categories