Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/53860-solved-problem-with-bulk-proccessing/
Share on other sites

Variable names can't start with a number.

 

Use arrays to pass the data eg

 

<?php
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='stampName[]'></td></tr>
    <tr><th>Face Value (pence):</th><td><input type='text' name='stampFace[]'></td></tr>
    <tr><th>Stanley Gibbons Number:</th><td><input type='text' name='stampSG[]'></td></tr>
    <tr><th>Image:</th><td>

    <input type='hidden' name='MAX_FILE_SIZE' value='300000' />
    <input type='file' name='pix[]' /><br />

    </td></tr>
    <tr><th>Copyright(optional):</th><td><input type='text' name='stampCopyright[]'></td></tr>
    </table>";
}?>

 

Note the "[]" at end of rach name

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.