I try to integrate Paybox credit card transaction solution.
I've tries at least 100 differents solutions (not kidding) but no one works and every time i got "Problème d'identification du commerce. Accès refusé !" message (in french).
Here is the most "stable" code I have :
<?php
function gen_hmac($site, $rang, $identifiant, $devise, $cmd, $porteur, $hash, $time, $total, $retour, $key) {
$msg = "PBX_SITE=". $site
."&PBX_RANG=". $rang
."&PBX_IDENTIFIANT=". $identifiant
."&PBC_TOTAL=". $total
."&PBX_DEVISE=". $devise
."&PBC_CMD=". $cmd
."&PBC_PORTEUR=". $porteur
."&PBC_RETOUR=". $retour
."&PBC_HASH=". $hash
."&PBC_TIME=" . $time ;
$binkey = pack("H*", $key);
echo "<!-- " . $msg . " -->";
$hmac = strtoupper(hash_hmac('sha512', $msg, $binkey));
echo "<!-- " . $hmac . " -->";
return $hmac;
}
// static
$site = 1999888;
$rang = 32;
//$identifiant = 110647233;
$identifiant = 107904482;
$devise = 978;
$hash = "SHA512";
$key = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$cmd = "TEST Paybox";
$porteur = "test#paybox.com";
$time = date("c");
//$time = "2011-02-28T11:01:50+01:00";
// variable
$total = 1000;
//$retour = "ref:R;trans:T;auto:A;tarif:M;abonnement:B;pays:Y;erreur:E";
$retour = "Mt:M;Ref:R;Auto:A;Erreur:E";
$hmac = gen_hmac($site, $rang, $identifiant, $devise, $cmd, $porteur, $hash, $time, $total, $retour, $key);
?>
<html>
<head>
<title>Paybox TEST</title>
</head>
<body>
<?php
//print_r(hash_algos());
?>
<form method="POST" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<!--<form method="POST" action="https://preprod-tpeweb.paybox.com/cgi/MYframepagepaiement_ip.cgi">-->
<!--<form method="POST" action="https://preprod-tpeweb.paybox.com/cgi/ChoixPaiementMobile.cgi">-->
<input type="hidden" name="PBX_SITE" value="<?php echo $site; ?>" />
<input type="hidden" name="PBX_RANG" value="<?php echo $rang; ?>" />
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $identifiant; ?>" />
<input type="hidden" name="PBX_TOTAL" value="<?php echo $total; ?>" />
<input type="hidden" name="PBX_DEVISE" value="<?php echo $devise; ?>" />
<input type="hidden" name="PBX_CMD" value="<?php echo $cmd; ?>" />
<input type="hidden" name="PBX_PORTEUR" value="<?php echo $porteur; ?>" />
<input type="hidden" name="PBX_RETOUR" value="<?php echo $retour; ?>" />
<input type="hidden" name="PBX_HASH" value="<?php echo $hash; ?>" />
<input type="hidden" name="PBX_TIME" value="<?php echo $time; ?>" />
<input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>" />
<!--<input type="hidden" name="PBX_REFUSE" value="http://test.fr/" />
<input type="hidden" name="PBX_ANNULE" value="http://test.fr/" />
<input type="hidden" name="PBX_EFFECTUE" value="http://test.fr/" />-->
<input type="submit" value="envoyer" />
</form>
</body>
</html>
Most statics values are from paybox test documentation.
So do you know what's wrong with my code or do you know how to have more details about what is wrong on what is send to paybox server ?
Sincerely
EDIT :
More details about my goal. My real need is to code this in java, but I had a few code sample in php which finally helped.
Now I try to find out how to generate a clean hmac/sha512 in java.
<?php
$key = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$binkey = pack("H*", $key);
echo strtoupper(hash_hmac('sha512', "ABC", $binkey));
?>
Outputs : 100A6A016A4B21AE120851D51C93B293D95B7D8A44B16ACBEFC2D1C9DF02B6F54FA3C2D6802E52FED5DF8652DDD244788A204682D2D1CE861FDA4E67F2792643
So how can I, in java, recreate the same hmac algorigthm ?
I've try a lot of things but no one achived my goal, but here is what I have currently :
private String generateHMAC( String datas )
{
// final Charset asciiCs = Charset.forName( "utf-8" );
Mac mac;
String result = "";
try
{
byte[] bytesKey = PayboxConstants.KEY.getBytes( );
final SecretKeySpec secretKey = new SecretKeySpec( bytesKey, "HmacSHA512" );
mac = Mac.getInstance( "HmacSHA512" );
mac.init( secretKey );
final byte[] macData = mac.doFinal( datas.getBytes( ) );
byte[] hex = new Hex( ).encode( macData );
result = new String( hex, "ISO-8859-1" );
}
catch ( final NoSuchAlgorithmException e )
{
AppLogService.error( e );
}
catch ( final InvalidKeyException e )
{
AppLogService.error( e );
}
catch ( UnsupportedEncodingException e )
{
AppLogService.error( e );
}
return result.toUpperCase( );
}
But its ouput is : AA6492987D7A7AC81109E877315414806F1973CC47B897ECE713171A25A11B279329B1BFF39EA72A5EFB7EDCD71D1F34D5AAC49999A780BD13F019ED99685B80
Which is definitly not equivalent to "cloned" php hmac algorithm.
So what can I add to my java code to make it compliant with its php equalivalent ?
EDIT :
Actually I managed to makes everything works together, and I available here :
http://dev.lutece.paris.fr/plugins/plugin-paybox/index.html
<section class="rl-box">
<div class="container padd-xs-0">
<div class="content-section1">
<div class="left-cont col-md-12 col-sm-12">
<div class="container-fluid">
<?php
$PBX_SITE = "1999888";
$PBX_RANG = "32";
$PBX_IDENTIFIANT = "your identifiant id";
$secretKeyTest = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$PBX_PORTEUR = "your-email";
$PAYBOX_DOMAIN_SERVER = "tpeweb.paybox.com";
$dateTime = date("c");
$PBX_TOTAL = 4000; //$_POST["PBX_TOTAL"]; // Amount
$PBX_DEVISE = 978;
//$PBX_CMD = $_POST["PBX_CMD"]."|".$_POST["user"]."|".$_POST["typed"]."|".$_POST["period"]."|".$_POST["id"]; // order ID no.
$PBX_CMD = 1; // order ID no.Eg: userid,order_id
$PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E";
$PBX_HASH = "SHA512";
$PBX_TIME = $dateTime;
//$PBX_EFFECTUE = "http://www.leader-underwriting.eu/payment/payment.php";
$msg = "PBX_SITE=$PBX_SITE" .
"&PBX_RANG=$PBX_RANG" .
"&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" .
"&PBX_TOTAL=$PBX_TOTAL" .
"&PBX_DEVISE=$PBX_DEVISE" .
"&PBX_CMD=$PBX_CMD" .
"&PBX_PORTEUR=$PBX_PORTEUR" .
"&PBX_RETOUR=$PBX_RETOUR" .
"&PBX_HASH=$PBX_HASH" .
"&PBX_TIME=$PBX_TIME";
$binKey = pack("H*", $secretKeyTest);
$hmac = strtoupper(hash_hmac('sha512', $msg, $binKey));
$cuu = str_replace(",", "", $ramount);
?>
<form method="POST" name="form_payment" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?php echo $PBX_TOTAL; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?php echo $PBX_CMD; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_PORTEUR" value="<?php echo $PBX_PORTEUR ?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR; ?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH; ?>">
<input type="hidden" name="PBX_TIME" value="<?php echo $PBX_TIME; ?>">
<input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>">
<button type="submit" class="btn btn-primary payment">
Payer
</button>
</form>
<center>
</center>
</div>
</div>
</div> <!-- .container-fluid -->
</div>
</div>
</div>
</section>
Related
im trying to remove a product from my shopping cart after adding them.
can you please help
this is my code
ADD TO CART
html:
<input type="hidden" name="pid" value="<?php echo $row['product_id']?>
<input type="double" name="weight" placeholder="Weight?" required>
PHP:
session_start();
$pid = $_POST['pid'];
$weight = $_POST['weight'];
$p = "pid";
$p .= (string) $pid;
$w = "weight";
$w .= (string) $pid;
$_SESSION[$p]=$pid;
$_SESSION[$w] = $weight;
if(isset($_SESSION)){
header('location:../shopping-cart.php');
}
after execution the product is added.
Display in Cart
foreach($_SESSION as $key => $values){
if(strpos($key, "pid") !== false){
$sql="select * from products where product_id = $_SESSION[$key]";
$result=$connect->query($sql);
$r = mysqli_fetch_assoc($result);
$w = "weight";
$w .= (string) $r['product_id'];
$weight = $_SESSION[$w];
HTML PHP CODE
<?php echo $r["product_name"];?>
<?php echo 'LBP '.number_format($r['product_price'],0)?>
<input type="hidden" id="unitprice" onchange="f();" value="<?php echo $r['product_price']?>">
<input type="text" onchange="f();" id="quantity" value="<?php echo $weight ?>">
<input type="submit" value="Delete">
<input type="hidden" name="pid" value="<?php echo $r['product_id'] ?>">
<input type="hidden" name="pweight" value="<?php echo $weight ?>">
remove from cart is not working
Any Help?
session_start();
$pidremove = $_POST['pid'];
$weightremove = $_POST['pweight'];
foreach($_SESSION as $key => $values){
if($_SESSION[$w]==$pidremove)
{
unset($_SESSION[$w]);
unset($_SESSION[$p]);
echo 'done';
}
}
HTML:
<input type="hidden" name="pid" value="<?php echo $row['product_id']; ?>" />
<input type="submit" name="remove" value="Remove">
PHP:
unset($_SESSION['pid' . $_POST['pid']]
unset($_SESSION['weight' . $_POST['pid']]
I'm trying to call the old values to be edited. What part am I wrong at?
<?php
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($db, "SELECT * FROM bookinfo WHERE BookNo='$BookNo'");
if (mysqli_num_rows($record) == 1 ) {
$n = mysqli_fetch_array($record);
$BookNo = $n['BookNo'];
$ISBN = $n['ISBN'];
$title = $n['title'];
$author = $n['author'];
$publisher = $n['publisher'];
$status = $n['status'];
$cost = $n['cost'];
}
}
?>
<a href="viewBook.php?edit=<?php echo $row['BookNo']; ?>" class="edit_btn" >Edit</a>
</td>
<?php
if (isset($_GET['edit'])) { ?>
<form method="post" action = "viewBook.php">
<input type="hidden" name="BookNo" value="<?php echo $BookNo; ?>">
<input type="text" name="ISBN" value="<?php echo $ISBN; ?>">
<input type="text" name="title" value="<?php echo $title; ?>">
<input type="text" name="author" value="<?php echo $author; ?>">
<input type="text" name="publisher" value="<?php echo $publisher; ?>">
<input type="text" name="status" value="<?php echo $status; ?>">
<input type="text" name="cost" value="<?php echo $cost; ?>">
<?php if ($update == true): ?>
<button class="btn" type="submit" name="update" style="background: #556B2F;" >update</button>
<?php else: ?>
<button class="btn" type="submit" name="save" >Save</button>
<?php endif ?>
<?php } ?>
</form>
So far, what it does is, when the user clicks the edit button, it just shows 6 text fields. I thought by doing what I did, it was supposed to show the details already filled in the textbox.
When you do
$record = mysqli_query($db, "SELECT * FROM bookinfo WHERE BookNo='$BookNo'");
$BookNo is not defined.
maybe you wanted to do something like this:
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($db, "SELECT * FROM bookinfo WHERE BookNo='$id'");
<form method="post" action = "viewBook.php">
your form method is "post" but you are checking $_GET You must check $_POST
if (isset($_GET['edit']))
you are passing value in $id And using $BookNo which not define.
only 6 input field will be show because first one is using hidden property.
<input type="hidden" name="BookNo" value="<?php echo $BookNo; ?>">
when you click on submit button data will be receive by $_POST
EDIT: When I print the $answer variable by itself it always returns the correct answer of the current question.
I am currently coding a PHP script that produces a simple, but completely random math quiz. How it works is that is gets two random numbers between 0-9 and a random operator from '-', '+', '*'. The user must enter into the text box the answer of the shown question. From here it's pretty straightforward to understand.
However, the issue I am having is that no matter what the user enters the only questions that are validated as correct are ones where the answer is 0.
Here is my code so far.
<?php
require 'functions.php';
$body = "";
$score = 0;
$count = 0;
if(isset($_POST['submit']))
{
$firstDigit = $_POST['lho'];
$secondDigit = $_POST['rho'];
$operator = $_POST['op'];
$userAnswer = $_POST['answer'];
$count = $_POST['count'];
$score = $_POST['score'];
$answer = evaluate($firstDigit, $secondDigit, $operator);
if($answer == $userAnswer)
{
$count++;
$score++;
$body .= "\n<h1>Congratulations!</h1>\n\n";
$body .= "$score out of $count";
}
else
{
$count++;
$body .= "\n<h1>Sorry!</h1>\n\n";
$body .= "$score out of $count";
}
}
header( 'Content-Type: text/html; charset=utf-8');
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
?>
<?php
include("./header.php");
?>
<h1>Math Quiz</h1> <br /> <br />
<?php
print $body;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h3><?php echo $firstDigit; ?> <?php echo $operator; ?> <?php echo $secondDigit; ?> = ?
<input type="text" name="answer" size="2" /></h3>
<p><input type="submit" name="submit" value="Try It!" />
<input type="hidden" name="lho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="rho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="op" value="<?php echo randop(); ?>" />
<input type="hidden" name="score" value="<?php echo $score++; ?>" />
<input type="hidden" name="count" value="<?php echo $count++; ?>" /></p>
</form>
<?php
include("./footer.php");
?>
My evaluate function is this:
function evaluate($d1, $d2, $op) {
switch($op) {
case '+' : // addition
$result = $d1 + $d2;
break;
case '-' : // subtraction
$result = $d1 - $d2;
break;
case '*' : // multiplication
$result = $d1 * $d2;
break;
default : // Unidentified, return safe value
$result = 0;
}
return $result;
}
Here is the randop() function and the randdigit() function:
/* Return a number in the range 0-9 inclusive
*/
function randdigit() {
return mt_rand(0,9);
} // end functionranddigit()
function randop(){
$ops = array('+', '-', '*');
// pick a random index between zero and highest index in array.
$randnum = mt_rand(0,sizeof($ops)-1);
return $ops[$randnum]; // Use the index to pick the operator
}
First on the 48th line :
<h3><?php echo $firstDigit; ?> <?php echo $operator; ?> <?php echo $secondDigit; ?> = ?
When you first load the form and until it has been submitted once,
$firstDigit, $operator, $secondDigit
Aren't set.
Then, this line wich is the equation to solve is filled with the old equation that needed to be solved AND your hidden fields are filled with new numbers, invisible to the user using randdigit() and randop().
<input type="hidden" name="lho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="rho" value="<?php echo randdigit(); ?>" />
<input type="hidden" name="op" value="<?php echo randop(); ?>" />
Here is the code that works well for me :
<?php
require 'functions.php';
$body = "";
$score = 0;
$count = 0;
$newFdigit = randdigit();
$newSdigit = randdigit();
$newOperator = randop();
if(isset($_POST['submit']))
{
$firstDigit = $_POST['lho'];
$secondDigit = $_POST['rho'];
$operator = $_POST['op'];
$userAnswer = $_POST['answer'];
$count = $_POST['count'];
$score = $_POST['score'];
$answer = evaluate($firstDigit, $secondDigit, $operator);
if($answer == $userAnswer)
{
$count++;
$score++;
$body .= "\n<h1>Congratulations!</h1>\n\n";
$body .= "$score out of $count";
}
else
{
$count++;
$body .= "\n<h1>Sorry!</h1>\n\n";
$body .= "$score out of $count";
}
}
header( 'Content-Type: text/html; charset=utf-8');
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
?>
<h1>Math Quiz</h1> <br /> <br />
<?php
print $body;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h3><?php echo $newFdigit; ?> <?php echo $newOperator; ?> <?php echo $newSdigit; ?> = ?
<input type="text" name="answer" size="2" /></h3>
<p><input type="submit" name="submit" value="Try It!" />
<input type="hidden" name="lho" value="<?php echo $newFdigit ?>" />
<input type="hidden" name="rho" value="<?php echo $newSdigit; ?>" />
<input type="hidden" name="op" value="<?php echo $newOperator; ?>" />
<input type="hidden" name="score" value="<?php echo $score++; ?>" />
<input type="hidden" name="count" value="<?php echo $count++; ?>" /></p>
</form>
I want to make a cofirm command page, that user after select the produse he cofirm the comand using the CONFIRM FORM, then to redirection him to the cofirm page, where he must write their dates to cofirm the command(the user dates)
So after i have a array in page cart.php
$cofirmaComanda .='<form action="cofirma_comanda.php" method="post">
<input name="prettotal" type="hidden" value="'. $pricetotal .'">
<input name="produseID" type="hidden" value="'. $item_id .'">
<input name="produseNume" type="hidden" value="'. $product_name .'">
<input name="size" type="hidden" value="'. $my_ArraySize .'">
<input name="cantitate" type="hidden" value="' . $each_item['quantity'] .'">
<input name="produse" type="hidden" value="'. $item_id .'">
<input type="submit" name="CofirmaComanda" value="cofirma_comanda"></form>';
then the cofirm page
<?php
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
?>
<?php
$pretTotal = $_POST["prettotal"];
$PRODUSE = $_POST["produseID"];
$produseNume = $_POST["produseNume"];
$size = $_POST["size"];
$cantitate = $_POST["cantitate"];
echo "ID: ".$PRODUSE."<br>";
echo "nume produs selectat: ".$produseNume." <br>";
echo $pretTotal." preata total in LEI<br>";
echo $cantitate." cantitate<br>";
echo $size." dimensiune<br>";
// Filter Function -------------------------------------------------------------------
function filterFunction ($var) {
$var = nl2br(htmlspecialchars($var));
$var = str_replace("/", "\\\\", $var);
$var = preg_replace("~/~", "\\\\", $var);
return $var;
}
$pretTotal = filterFunction($pretTotal);
$PRODUSE = filterFunction($PRODUSE);
$produseNume = filterFunction($produseNume);
$size = filterFunction($size);
$cantitate = filterFunction($cantitate);
if(isset($_SESSION["sumbitDateClienti"])){
$nume = $_POST["nume_client"];
$comanda = 'IDprodus: '.$PRODUSE.' / produseNume: '.$produseNume.' / cantitate: '.$cantitate.' / dimensiune: '.$size.' ';
$stmt = $con->prepare("INSERT comanda (pret_comanda, comanda) VALUES (?, ?)");
// TODO check that $stmt creation succeeded
// "s" means the database expects a string
$stmt->bind_param("ss", $pretTotal, $comanda);
$stmt->execute();
if($stmt->execute()) {
echo "<strong>succes</strong> pagina a fost creata\n titlu: n<a href='admin_index_istorie.php'><strong>Inapoi la pagina de modificare istorie</strong></a>";
}
else {
echo "eroare";
}
$stmt->close();
}
else{
echo "completeaza forum pentru a finaliza comanda";
}
?>
the form on the cofirm page
<form action="" method="post">
nume: <input name="nume_client" type="text">
<input type="hidden" name="prettotal" value="<?php echo $_POST['prettotal'] ?>">
<input type="hidden" name="produseID" value="<?php echo $_POST['produseID']; ?>">
<input type="hidden" name="produseNume" value="<?php echo $_POST['produseNume']; ?>">
<input type="hidden" name="cantitate" value="<?php echo $_POST['cantitate']; ?>">
<input type="hidden" name="size" value="<?php echo $_POST['size']; ?>">
<input type="submit" name="sumbitDateClienti" value="ok">
</form>
I am stucking in this problem because if i put a name on the field is noting doing, doesnt insert the query in the database, and also doesnt give me the else return with the error
$va_fields = array();
$c = 0;
$field_num = 'field-'.$c;
settype($c,"integer");
while (isset($_POST[$field_num])){
$posted_field = $_POST[$field_num];
$va_fields = array( $c => $posted_field);
echo $c.': ';
echo '$posted_field: '.$posted_field;
$c+=1;
$field_num = 'field-'.$c;
echo ' <br /> va_fields - c:'.$va_fields[$c];
echo ' <br /> ';
}
For some reason, I cannot for the life of me get the variable $posted_fields into an array.
The values of $posted_field are what I need them to be, so I'm getting the data from the post. Then I try to store them in an array, and check the array and they aren't there. What am I doing wrong?
Edit: here's my form:
<form method="post" action="<?php echo get_site_url(); ?>/wp-admin/admin-post.php">
<input type="hidden" name="action" value="cpt_field_opts" />
<!-- some inputs here ... -->
<?php wp_nonce_field( 'cpt_field_opts', '_wp_nonce' ); ?>
<input type="hidden" name="post_type" value="<?php echo $post_type; ?>">
<input type="hidden" name="origin" value="<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>" />
<?php
$c = 0;
foreach ($fields as $field){
?>
<input type="textarea" id="field-<?php echo $c; ?>" name="field-<?php echo $c; ?>" value="<?php echo $field; ?>" size="25" /></br>
<?php
$c += 1;
}
?>
<input type="submit" value="Submit" >
</form>
<form method="post" action="<?php echo get_site_url(); ?>/wp-admin/admin-post.php">
<?php wp_nonce_field( 'cpt_field_opts_new', '_wp_nonce_2' ); ?>
<input type="hidden" name="post_type" value="<?php echo $post_type; ?>" />
<input type="hidden" name="action" value="cpt_field_opts_new" />
<input type="hidden" name="origin" value="<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>" />
<input type="submit" value="New" />
</form>
Many people are telling me to rewrite the array as this line:
$va_fields[$c] = $posted_field;
Which I have done, but I also started out with that and it still wasn't working
If you have a bunch of values in $_POST with names like "field-0", "field-1", etc, and you're trying to get them into an array:
$c = 0;
while (isset($_POST["field-$c"])){
// This creates a new element in $va_fields with key=$c and value=$_POST["field-$c"]
$va_fields[$c] = $_POST["field-$c"];
}
var_dump($va_fields); // should show you the array you want
But really, it would be easier to just modify your form to use inputs with name=field[] instead of numbering them. Then you would already have the array in $_POST['fields'] without having to do anything.
It is simple just iterate the $_POST array
<?php
$va_fields = array();
$c=0;
foreach($_POST as $val){
echo '$posted_field: '. $val;
$va_fields[$c] = $val;
}
var_dump($va_fields);
?>