inserting from dynamic text boxes
Posted: Tue Mar 23, 2004 3:27 pm
I am having trouble with insterting from a dynamic text box. The user inputs a number into these text boxes and then it is saved into the database. Here is my code.
For the naming of the text box
This works fine. It actually gets the value from the prior page.
My insert statement on the page after this is what doesn't work
Any solutions???
For the naming of the text box
Code: Select all
<?php
mysql_select_db($database_connection, $connection);
$query_Recordset1 = "SELECT * FROM Item_Master WHERE Item_Type = 'Supplies'";
$Recordset1 = mysql_query($query_Recordset1, $connection) or die(mysql_error());
//$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
for ($i=0; $i<$totalRows_Recordset1; $i++){
$row_Recordset1 = mysql_fetch_array($Recordset1);
echo "<tr>";
echo "<td>";
echo "<input name='$row_Recordset1[Item_Name]' value='$row_Recordset1[Item_Name]' type='text' readonly='true'>";
echo "</td>";
for ($t=0; $t <= 3; $t++)
{
echo "<td>";
echo ('<input name="number_'.$i.$t.'" value="'.$_POST[number_.$i.$t].'" type="text" size="7">');
echo "</td>";
}
echo "<td>";
$answer = ($_POST[number_.$i.'0'] + $_POST[number_.$i.'1'] - $_POST[number_.$i.'2']) - $_POST[number_.$i.'3'];
echo $answer;
echo "</td>";
}
?>My insert statement on the page after this is what doesn't work
Code: Select all
<?php
for ($i=0; $i<$totalRows_Recordset1; $i++){
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO Missing_Analysis (PC_Number, Item_Code, Weekly_Missing_Date, Open_Qty, Stock_Qty, Sold_Qty, Actual_Count, Missing_Qty ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['PC'], "int"),
GetSQLValueString($_POST['$row_Recordset1[Item_Name]'], "text"),
GetSQLValueString($_POST['Missing_Date'], "date"),
GetSQLValueString($_POST['number_.$i.0.'], "int"),
GetSQLValueString($_POST['number_.$i.1.'], "int"),
GetSQLValueString($_POST['number_.$i.2.'], "int"),
GetSQLValueString($_POST['number_.$i.3.'], "int"),
GetSQLValueString($_POST['number_.$i.4.'], "int"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
}
$insertGoTo = "Confirmation.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
mysql_free_result($Recordset1);
header(sprintf("Location: %s", $insertGoTo));
}
?>