Jump to content

$_POST identical text fields into database


Schlo_50

Recommended Posts

I have a list which is pulled and displayed from my MS Access database. Next to each row, is a text field which appears evertime a new row is displayed and that is called 'code'.

 

I want any text field filled in by the user to be sent into my database, into one field all separated by commas. I have made an attempt at this in the second example script but it needs tweaking.

 

I have here my script which pulls the list from my database:

 

<?php
$sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName") or die (odbc_errormsg());

$prevCat='';
while($row = odbc_fetch_array($sql2))
{
$Category = $row["CategoryName"];
$ProductId = $row["ProductId"];
$ProductName = $row["ProductName"];
$Price = $row["Price"];

// has category changed
// if so, print it
if ($Category != $prevCat)  {
	echo "<h2>$Category</h2>";
}
echo  'Item Code: ', $ProductId, '<br/>Item Name:  ', $ProductName, '<br/><br/>Price: £', $Price, '<input name="code" type="text" size="2" /> <input name="quan" type="text" size="5" /><br/><br/>';

$prevCat = $Category;
}
?>

 

This is the code i have to send all of the inputted data in 'code' to my database, which unfortunately doesn't upload the user input corectly.

 

<?php
if ($_POST[submit] == "Submit") 
{
//Collect form data, having problems here!

$code = substr($_POST['code'],0);
$codeb = substr($_POST['code'],0);
$code = "$code,$codeb";
//SQL Statement

$conn = odbc_connect('DB', 'root', '') or die('Could not Connect to ODBC Database!');

$sql = "INSERT INTO Order1 " . "(ProductNotes) VALUES ('$code')";

//Execute SQL Statement and store results as a recordset

$rs = @odbc_exec($conn,$sql);

if (!$rs)
{

echo "An error has occured. Please try again";

}

else

{

echo "The record was successfully inserted.";

}
odbc_close($conn);
}
?>

 

Thanks in advance guys

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.