Hi there folks! I was wondering if anyone encountered a similar issue, I will try to explain it.
All the code below works with no errors, except that any HTML input fields that are generated dynamically are not being passed on to the PHP script defined in Action="....." variable. The variables that are dynamically generated are called order_qty1, order_qty2 etc. They are not available to the PHP script via $_POST[...]. I am providing all the code for reference. Static fields work fine, by the way, in the same example. Do you know any workaround for this?
Thanks very much!
Eliott.
------------------------------------------------
Source for the PHP code:
<?php
session_start();
include ('PrintCustAndShipInfo.php');
print('----- This dynamic code does not get the variable -----');print('<br>');
for ( $i=1; $i < 4; $i++ ) {
$ord_qty = $_POST['order_qty'.$i];
print $_POST[$ord_qty];
print '<br>';
}
$var1=1;
print('----- This static code gets the variable -----');print('<br>');
print ($_POST['test'.$var1]);
print '<br>';
?>
<form method="post" action="ProcessCustForm3.php">
<br>Credit Card Information<br>
Name on card: <input type="text" name="credit_card_name"><br>
Card Number: <input type="text" name="credit_card_number"><br>
Expiry date: <input type="text" name="credit_card_expdate"><br>
<input type="submit" value="Finish"><br>
</form>
------------------------------------------------
Source for Dynamic HTML:
<html>
<body>
<form method="post" action="ProcessCustForm2.php">
<?php
session_start();
//now, let's register our session variables
session_register('order_fname');
session_register('order_lname');
session_register('order_email');
session_register('order_phone');
session_register('order_address');
session_register('order_city');
session_register('order_state');
session_register('order_country');
session_register('order_zip');
session_register('order_shipmethod');
//Customer information
$_SESSION['order_fname'] = $_POST['order_fname'];
$_SESSION['order_lname'] = $_POST['order_lname'];
$_SESSION['order_email'] = $_POST['order_email'];
$_SESSION['order_phone'] = $_POST['order_phone'];
// Shipping information
$_SESSION['order_address'] = $_POST['order_address'];
$_SESSION['order_city'] = $_POST['order_city'];
$_SESSION['order_state'] = $_POST['order_state'];
$_SESSION['order_country'] = $_POST['order_country'];
$_SESSION['order_zip'] = $_POST['order_zip'];
$_SESSION['order_shipmethod'] = $_POST['order_shipmethod'];
include( 'PrintCustAndShipInfo.php' );
getInv();
function getInv() {
// setup connection
$mysql_host = "mysql2.000webhost.com";
$mysql_database = "a5270158_order1";
$mysql_user = "a5270158_order1";
$mysql_password = "breathe123";
// connect to db
$con = mysql_connect($mysql_host,$mysql_user,$mysql_passw ord);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
else {
// connect to database
$db_found = mysql_select_db($mysql_database);
if ($db_found) {
// read records from order_inventory table into a list
$sql = "SELECT * from order_inventory";
$result = mysql_query($sql);
$line_num = 1;
print ('<table border=1>');
print ('<tr>'); print("\n");
print ('<td colspan="5">');print("\n");
print ('Select the items that you wish to order');print("\n");
print ('</tr>');print("\n");
while ($db_field = mysql_fetch_assoc($result)) {
$order_qty = '<input type="text" '.'name="order_qty' . $line_num . '" value=0 size=3 maxlength=3>';
print '<tr>'; print("\n");
print '<td>'; print $db_field['id']; print '</td>'; print("\n");
print '<td>'; print $order_qty; print '</td>'; print("\n");
print '<td>'; print $db_field['title']; print '</td>'; print("\n");
print '<td>'; print $db_field['author']; print '</td>'; print("\n");
print '<td>'; print $db_field['price'] ; print '</td>'; print("\n");
print '</tr>'; print("\n");
print '<br>'; print("\n");
$line_num++;
}
print '</table>';
}
else {
print "Database NOT Found"; print ('<p>');
}
// close connection
mysql_close($con);
}
}
?>
<br>
<input type="text" name="test1" value="testing post">
<input type="submit" value="Proceed to step #3">
</form>
</body>
</html>
------------------------------------------------
HTML Rendered by the browser:
<html>
<body>
<form method="post" action="ProcessCustForm2.php">
<table width="60%" border="1"><tr><td>Customer Information</td><td>Shipping Information</td></tr><tr><td><br><br><br>999-999-9999<br></td><td><br><br><br>USA<br><br>1<br></td></tr></table><table border=1><tr>
<td colspan="5">
Select the items that you wish to order
</tr>
<tr>
<td>1</td>
<td><input type="text" name="order_qty1" value=0 size=3 maxlength=3></td>
<td>Alice in Wonderland</td>
<td>Oolon Colluphid</td>
<td>9.99</td>
</tr>
<br>
<tr>
<td>2</td>
<td><input type="text" name="order_qty2" value=0 size=3 maxlength=3></td>
<td>The Secret Garden</td>
<td>Oolon Colluphid</td>
<td>9.99</td>
</tr>
<br>
<tr>
<td>3</td>
<td><input type="text" name="order_qty3" value=0 size=3 maxlength=3></td>
<td>The Wind In The Willows</td>
<td>Oolon Colluphid</td>
<td>9.99</td>
</tr>
<br>
</table>
<br>
<input type="text" name="test1" value="testing post">
<input type="submit" value="Proceed to step #3">
</form>
</body>
</html>
<!--
www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->