I have a program to add 'stamps' to sets of stamps. First you enter the number of stamps in the set(addStamp.php). Then it displays that many sets of forms (addStamp.php?do=input). Finally these are all inputted to a database (addStamp.php?do=database).
The problem is processing the multiple sets of data. I've tried something (see the $tn 's in the code) but can't get it to work. Can anyone help me out?
<html>
<head>
<title>Add Stamps to a Set</title>
<link rel='stylesheet' type='text/css' href='/stylesheet.css' title='Stylesheet'>
</head>
<body background='marble.jpg'>
<center>
<?php
if ($_GET['do']=="")
{
echo "<p class='headertext'>Add a New Set to the Site<p>
<form action='addStamp.php?do=input' method='POST'>
<table>
<tr><th>No of Stamps in Set :</th><td><input type='text' name='numberinset'></td></tr>
</table>
<input type='submit' value='Continue'>
</form>";
die();
}
elseif ($_GET['do']=="input")
{
echo "<p class='headertext'>Add a New Set to the Site<p>
<form action='addStamp.php?do=database' method='POST' enctype='multipart/form-data'>";
for($tn=1;$tn<=$_POST['numberinset'];$tn++)
{
echo "<table><tr><th colspan=2>$tn:</th></tr>
<tr><th>Stamp Name:</th><td><input type='text' name='{$tn}stampName'></td></tr>
<tr><th>Face Value (pence):</th><td><input type='text' name='{$tn}stampFace'></td></tr>
<tr><th>Stanley Gibbons Number:</th><td><input type='text' name='{$tn}stampSG'></td></tr>
<tr><th>Image:</th><td>
<input type='hidden' name='MAX_FILE_SIZE' value='300000' />
<input type='file' name='{$tn}pix' /><br />
</td></tr>
<tr><th>Copyright(optional):</th><td><input type='text' name='{$tn}stampCopyright'></td></tr>
</table>";
}
echo "<input type='submit' value='Add Stamps' name='Upload'></form>";
die();
}
elseif ($_GET['do']=="database")
{
include("misc2.inc.php");
$cxn = mysqli_connect($host,$user,$passwd,$dbname)
or die ("Coudn't connect to server.");
// Code to help with upload - use later
$obvious = 3;
if($obvious == 4)
{
if(!isset($_POST['Upload']))
{
echo "No File Selected";
}
else
{
if($_FILES['pix']['tmp_name'] == "none")
{
echo "<b>File did not successfully upload. Check the
file size. File must be less than 500K.<br>";
include("form_upload.inc");
exit();
}
if(!ereg("image",$_FILES['pix']['type']))
{
echo "<b>File is not a picture. Please try another
file.</b><br>";
include("form_upload.inc");
exit();
}
else
{
$destination = $_FILES['pix']['name'];
$temp_file = $_FILES['pix']['tmp_name'];
move_uploaded_file($temp_file,$destination);
echo "<p><b>The file has successfully uploaded:</b>
{$_FILES['pix']['name']}
({$_FILES['pix']['size']})</p>";
}
}
}
// End of upload helping code
}
// Below this point not applicable (reference for building database part of app)
else
{
$setYear = $_POST['year'];
$setMonth = $_POST['month'];
$setDay = $_POST['day'];
$setName = $_POST['name'];
$noStamps = $_POST['noStamps'];
$setIllustration = $_POST['illustration'];
$setDesign = $_POST['design'];
$setFormat = $_POST['shape'];
$setWidth = $_POST['width'];
$setHeight = $_POST['height'];
$setPrinter = $_POST['printer'];
$setPrintProcess = $_POST['process'];
$setPerfsWidth = $_POST['perfswide'];
$setPerfsHeight = $_POST['perfstall'];
$setGum = $_POST['gum'];
$noSheet = $_POST['nopersheet'];
include("misc2.inc.php");
$cxn = mysqli_connect($host,$user,$passwd,$dbname)
or die ("Coudn't connect to server.");
$query = "INSERT INTO sets (setYear,setMonth,setDay,setName,noStamps,setIllustration,setDesign,setFormat,setWidth,setHeight,setPrinter,setPrintProcess,setPerfsWidth,setPerfsHeight,setGum,noSheet)
VALUES ('$setYear','$setMonth','$setDay','$setName','$noStamps','$setIllustration','$setDesign','$setFormat','$setWidth','$setHeight','$setPrinter','$setPrintProcess','$setPerfsWidth','$setPerfsHeight','$setGum','$noSheet')";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query.");
echo "Set Added";
echo "<p class='sitelinks'><a href='addSet.php'>Add another!</a><p><a href='sets.php'>View all Sets!</a>";
}
// End of non applicable code
?>
</center>
</body>
</html>