inserting from dynamic text boxes

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
squirto28
Forum Newbie
Posts: 11
Joined: Mon Mar 22, 2004 9:41 pm

inserting from dynamic text boxes

Post by squirto28 »

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

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>";
} 

?>
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

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));
}

?>
Any solutions???
Post Reply