Multiline post to MySQL

I 've been trying to get a grid “like” form to post to MySQL, but keeps failing. Please can somebody help?

Heres the Form:
[php]




Equipment Sheet

Company Name Company Address
Contact Name
Contact Phone Number
Contact Mobile Number Contact Email Address
Equipment Items Type Of Unit Unit Description Unit Manufacturer Model Number Serial Number Cooling Period Refrigeration Type Chiller Oil Type Chiller Oil Capacity

And here is the PHP:

<?php $host='localhost'; $username='root'; $password="root"; $database = 'my_database'; $company=$_POST['company']; $companyAddress=$_POST['companyAddress']; $contactname=$_POST['contactname']; $contactphonenumber=$_POST['contactphonenumber']; $contactmobilenumber=$_POST['contactmobilenumber']; $contactemail=$_POST['contactemail']; $equipmentunits=$_POST['equipmentunits']; $equipmentunits2=$_POST['equipmentunits2']; $equipmentunits3=$_POST['equipmentunits3']; $equipmentunits4=$_POST['equipmentunits4']; $equipmentunits5=$_POST['equipmentunits5']; $equipmentunits6=$_POST['equipmentunits6']; $equipmentunits7=$_POST['equipmentunits7']; $equipmentunits8=$_POST['equipmentunits8']; $typeofunits=$_POST['typeofunits']; $typeofunits2=$_POST['typeofunits2']; $typeofunits3=$_POST['typeofunits3']; $typeofunits4=$_POST['typeofunits4']; $typeofunits5=$_POST['typeofunits5']; $typeofunits6=$_POST['typeofunits6']; $typeofunits7=$_POST['typeofunits7']; $typeofunits8=$_POST['typeofunits8']; $unitdescription=$_POST['unitdescription']; $unitdescription2=$_POST['unitdescription2']; $unitdescription3=$_POST['unitdescription3']; $unitdescription4=$_POST['unitdescription4']; $unitdescription5=$_POST['unitdescription5']; $unitdescription6=$_POST['unitdescription6']; $unitdescription7=$_POST['unitdescription7']; $unitdescription8=$_POST['unitdescription8']; $unitmanufacturer=$_POST['unitmanufacturer']; $unitmanufacturer2=$_POST['unitmanufacturer2']; $unitmanufacturer3=$_POST['unitmanufacturer3']; $unitmanufacturer4=$_POST['unitmanufacturer4']; $unitmanufacturer5=$_POST['unitmanufacturer5']; $unitmanufacturer6=$_POST['unitmanufacturer6']; $unitmanufacturer7=$_POST['unitmanufacturer7']; $unitmanufacturer8=$_POST['unitmanufacturer8']; $modelnumber=$_POST['modelnumber']; $modelnumber2=$_POST['modelnumber2']; $modelnumber3=$_POST['modelnumber3']; $modelnumber4=$_POST['modelnumber4']; $modelnumber5=$_POST['modelnumber5']; $modelnumber6=$_POST['modelnumber6']; $modelnumber7=$_POST['modelnumber7']; $modelnumber8=$_POST['modelnumber8']; $serialnumber=$_POST['serialnumber']; $serialnumber2=$_POST['serialnumber2']; $serialnumber3=$_POST['serialnumber3']; $serialnumber4=$_POST['serialnumber4']; $serialnumber5=$_POST['serialnumber5']; $serialnumber6=$_POST['serialnumber6']; $serialnumber7=$_POST['serialnumber7']; $serialnumber8=$_POST['serialnumber8']; $coolingperiod=$_POST['coolingperiod']; $coolingperiod2=$_POST['coolingperiod2']; $coolingperiod3=$_POST['coolingperiod3']; $coolingperiod4=$_POST['coolingperiod4']; $coolingperiod5=$_POST['coolingperiod5']; $coolingperiod6=$_POST['coolingperiod6']; $coolingperiod7=$_POST['coolingperiod7']; $coolingperiod8=$_POST['coolingperiod8']; $refrigerationtype=$_POST['refrigerationtype']; $refrigerationtype2=$_POST['refrigerationtype']; $refrigerationtype3=$_POST['refrigerationtype3']; $refrigerationtype4=$_POST['refrigerationtype4']; $refrigerationtype5=$_POST['refrigerationtype5']; $refrigerationtype6=$_POST['refrigerationtype6']; $refrigerationtype7=$_POST['refrigerationtype7']; $refrigerationtype8=$_POST['refrigerationtype8']; $chilleroiltype=$_POST['chilleroiltype']; $chilleroiltype2=$_POST['chilleroiltype2']; $chilleroiltype3=$_POST['chilleroiltype3']; $chilleroiltype4=$_POST['chilleroiltype4']; $chilleroiltype5=$_POST['chilleroiltype5']; $chilleroiltype6=$_POST['chilleroiltype6']; $chilleroiltype7=$_POST['chilleroiltype7']; $chilleroiltype8=$_POST['chilleroiltype8']; $chilleroilcapacity=$_POST['chilleroilcapacity']; $chilleroilcapacity2=$_POST['chilleroilcapacity2']; $chilleroilcapacity3=$_POST['chilleroilcapacity3']; $chilleroilcapacity4=$_POST['chilleroilcapacity4']; $chilleroilcapacity5=$_POST['chilleroilcapacity5']; $chilleroilcapacity6=$_POST['chilleroilcapacity6']; $chilleroilcapacity7=$_POST['chilleroilcapacity7']; $chilleroilcapacity8=$_POST['chilleroilcapacity8']; mysql_connect($host, $username, $password) or die ('Error connecting to mysql'); mysql_select_db($database) or die( "Unable to select database"); $query ="INSERT INTO item(id,equipmentunits,company,companyAddress,contactname,contactphonenumber,contactmobilenumber,contactemail,equipmentunits,typeofunits,unitdescription,unitmanufacturer,modelnumber,serialnumber,coolingperiod,refrigerationtype,chilleroiltype,chilleroilcapacity) VALUES ('$id', '$company', '$companyAddress', '$contactname', '$contactphonenumber', '$contactmobilenumber', '$contactemail', ('','$equipmentunits', '$typeofunits', '$unitdescription','$unitmanufacturer','$modelnumber','$serialnumber','$coolingperiod','$refrigerationtype','$chilleroiltype''$chilleroilcapacity'), ('','$equipmentunits2', '$typeofunits2', '$unitdescription2','$unitmanufacturer2','$modelnumber2','$serialnumber','$coolingperiod2','$refrigerationtype2','$chilleroiltype2','$chilleroilcapacity2'), ('','$equipmentunits3', '$typeofunits3', '$unitdescription3','$unitmanufacturer3','$modelnumber3','$serialnumber3','$coolingperiod3','$refrigerationtype3','$chilleroiltype2''$chilleroilcapacity3'), ('','$equipmentunits4', '$typeofunits4', '$unitdescription4','$unitmanufacturer4','$modelnumber4','$serialnumber4','$coolingperiod4','$refrigerationtype4','$chilleroiltype2''$chilleroilcapacity4'), ('','$equipmentunits5', '$typeofunits5', '$unitdescription5','$unitmanufacturer5','$modelnumber5','$serialnumber5','$coolingperiod5','$refrigerationtype5','$chilleroiltype2''$chilleroilcapacity5'), ('','$equipmentunits6', '$typeofunits6', '$unitdescription6','$unitmanufacturer6','$modelnumber6','$serialnumber6','$coolingperiod6','$refrigerationtype6','$chilleroiltype2''$chilleroilcapacity6'), ('','$equipmentunits7', '$typeofunits7', '$unitdescription7','$unitmanufacturer7','$modelnumber7','$serialnumber7','$coolingperiod7','$refrigerationtype7','$chilleroiltype2''$chilleroilcapacity7'), ('','$equipmentunits8', '$typeofunits8', '$unitdescription8','$unitmanufacturer8','$modelnumber8','$serialnumber'8,'$coolingperiod8','$refrigerationtype8','$chilleroiltype2''$chilleroilcapacity8')"; mysql_query($query); if($query){ echo "Successful"; echo "
"; } else { echo "ERROR"; } ?> <?php // close connection mysql_close(); ?>[/php]

Aside from some html issues, whats the problem you’re having?

(fixed the html issues)

<div style='text-align: center;'>
<form action="process.php" method="post">
   <table style='background-color: #0b2d04; text-align: left;'">
       <tr bgcolor="#dbaa7a">
           <td align="center" colspan="20"><h2>Equipment Sheet</h2><br /></td>
       </tr>
       <tr>
          <th><span style="color: white;">Company Name</span></th>
          <td><input name="company" type="text"/></td>
          <th><span style="color: white;">Company Address</span></th>
          <td><textarea name=companyAddress type="text"></textarea></td>
       </tr> // missing this /tr
       <tr>
          <th><span style="color: white;">Contact Name</span></th>
          <td><input name="contactname" type="text" /></td>
       </tr> // missing this /tr
       <tr>
          <th><span style="color: white;">Contact Phone Number</span></th>
          <td><input name="contactphonenumber" type="text"/></td></td>
       </tr> // missing this /tr
       <tr>
          <th><span style="color: white;">Contact Mobile Number</span></th>
          <td><input name="contactmobilenumber" type="text" /></th> // missing this /th
          <th><span style="color: white;">Contact Email Address</span></th>
          <td><input name="contactemail" type="text" />
       </tr>
       <tr>
          <th><span style="color: white;">Equipment Items</span></th>
          <th><span style="color: white;">Type Of Unit</span></th>
          <th><span style="color: white;">Unit Description</span></th>
          <th><span style="color: white;">Unit Manufacturer</span></th>
          <th><span style="color: white;">Model Number</span></th>
          <th><span style="color: white;">Serial Number</span></th>
          <th><span style="color: white;">Cooling Period</span></th>
          <th><span style="color: white;">Refrigeration Type</span></th>
          <th><span style="color: white;">Chiller Oil Type</span></th>
          <th><span style="color: white;">Chiller Oil Capacity</span></th>
       </tr>
       <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits" readonly="readonly" type="text" value="Equipment 1" /></td>
          <td><input name="typeofunits" type="text" /></td>
          <td><input name="unitdescription" type="text" /></td>
          <td><input name="unitmanufacturer" type="text" /></td>
          <td><input name="modelnumber" type="text" /></td>
          <td><input name="serialnumber" type="text" /></td>
          <td><input name="coolingperiod" type="text" /></td>
          <td><input name="refrigerationtype" type="text" /></td>
          <td><input name="chilleroiltype" type="text" /></td>
          <td><input name="chilleroilcapacity" type="text" /></td>
       </tr>
       <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits2" readonly="readonly" type="text" value="Equipment 2" /></td>
          <td><input name="typeofunits2" type="text" /></td>
          <td><input name="unitdescription2" type="text" /></td>
          <td><input name="unitmanufacturer2" type="text" /></td>
          <td><input name="modelnumber2" type="text" /></td>
          <td><input name="serialnumber2" type="text" /></td>
          <td><input name="coolingperiod2" type="text" /></td>
          <td><input name="refrigerationtype2" type="text" /></td>
          <td><input name="chilleroiltype2" type="text" /></td>
          <td><input name="chilleroilcapacity2" type="text" /></td>
       </tr>
       <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits3" readonly="readonly" type="text" value="Equipment 3" /></td>
          <td><input name="typeofunits3" type="text" /></td>
          <td><input name="unitdescription3" type="text" /></td>
          <td><input name="unitmanufacturer3" type="text" /></td>
          <td><input name="modelnumber3" type="text" /></td>
          <td><input name="serialnumber3" type="text" /></td>
          <td><input name="coolingperiod3" type="text" /></td>
          <td><input name="refrigerationtype3" type="text" /></td>
          <td><input name="chilleroiltype3" type="text" /></td>
          <td><input name="chilleroilcapacity3" type="text" /></td>
       </tr>
       <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits4" readonly="readonly" type="text" value="Equipment 4" /></td>
          <td><input name="typeofunits4" type="text" /></td>
          <td><input name="unitdescription4" type="text" /></td>
          <td><input name="unitmanufacturer4" type="text" /></td>
          <td><input name="modelnumber4" type="text" /></td>
          <td><input name="serialnumber4" type="text" /></td>
          <td><input name="coolingperiod4" type="text" /></td>
          <td><input name="refrigerationtype4" type="text" /></td>
          <td><input name="chilleroiltype4" type="text" /></td>
          <td><input name="chilleroilcapacity4" type="text" /></td>
       </tr>
       <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits5" readonly="readonly" type="text" value="Equipment 5" /></td>
          <td><input name="typeofunits5" type="text" /></td>
          <td><input name="unitdescription5" type="text" /></td>
          <td><input name="unitmanufacturer5" type="text" /></td>
          <td><input name="modelnumber5" type="text" /></td>
          <td><input name="serialnumber5" type="text" /></td>
          <td><input name="coolingperiod5" type="text" /></td>
          <td><input name="refrigerationtype5" type="text" /></td>
          <td><input name="chilleroiltype5" type="text" /></td>
          <td><input name="chilleroilcapacity5" type="text" /></td>
        </tr>
        <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits6" readonly="readonly" type="text" value="Equipment 6" /></td>
          <td><input name="typeofunits6" type="text" /></td>
          <td><input name="unitdescription6" type="text" /></td>
          <td><input name="unitmanufacturer6" type="text" /></td>
          <td><input name="modelnumber6" type="text" /></td>
          <td><input name="serialnumber6" type="text" /></td>
          <td><input name="coolingperiod6" type="text" /></td>
          <td><input name="refrigerationtype6" type="text" /></td>
          <td><input name="chilleroiltype6" type="text" /></td>
          <td><input name="chilleroilcapacity6" type="text" /></td>
        </tr>
        <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits7" readonly="readonly" type="text" value="Equipment 7" /></td>
          <td><input name="typeofunits7" type="text" /></td>
          <td><input name="unitdescription7" type="text" /></td>
          <td><input name="unitmanufacturer7" type="text" /></td>
          <td><input name="modelnumber7" type="text" /></td>
          <td><input name="serialnumber7" type="text" /></td>
          <td><input name="coolingperiod7" type="text" /></td>
          <td><input name="refrigerationtype7" type="text" /></td>
          <td><input name="chilleroiltype7" type="text" /></td>
          <td><input name="chilleroilcapacity7" type="text" /></td>
        </tr>
        <tr bgcolor="#CCCCCC">
          <td><input name="equipmentunits8" readonly="readonly" type="text" value="Equipment 8" /></td>
          <td><input name="typeofunits8" type="text" /></td>
          <td><input name="unitdescription8" type="text" /></td>
          <td><input name="unitmanufacturer8" type="text" /></td>
          <td><input name="modelnumber8" type="text" /></td>
          <td><input name="serialnumber8" type="text" /></td>
          <td><input name="coolingperiod8" type="text" /></td>
          <td><input name="refrigerationtype8" type="text" /></td>
          <td><input name="chilleroiltype8" type="text" /></td>
          <td><input name="chilleroilcapacity8" type="text" /></td>
        </tr>
        <tr bgcolor="#dbaa7a"><td align="right" colspan="20"><input type="submit" value="Enter" name='submit' /></td>
         </tr>
    </table>
</form>
</div>

And here is the PHP:
[php]

<?php mysql_connect($host, $username, $password) or die ('Error connecting to mysql'); mysql_select_db($database) or die( "Unable to select database"); if(isset($_POST['submit'])) { $host='localhost'; $username='root'; $password="root"; $database = 'my_database'; $company=$_POST['company']; $companyAddress=$_POST['companyAddress']; $contactname=$_POST['contactname']; $contactphonenumber=$_POST['contactphonenumber']; $contactmobilenumber=$_POST['contactmobilenumber']; $contactemail=$_POST['contactemail']; $equipmentunits=$_POST['equipmentunits']; $equipmentunits2=$_POST['equipmentunits2']; $equipmentunits3=$_POST['equipmentunits3']; $equipmentunits4=$_POST['equipmentunits4']; $equipmentunits5=$_POST['equipmentunits5']; $equipmentunits6=$_POST['equipmentunits6']; $equipmentunits7=$_POST['equipmentunits7']; $equipmentunits8=$_POST['equipmentunits8']; $typeofunits=$_POST['typeofunits']; $typeofunits2=$_POST['typeofunits2']; $typeofunits3=$_POST['typeofunits3']; $typeofunits4=$_POST['typeofunits4']; $typeofunits5=$_POST['typeofunits5']; $typeofunits6=$_POST['typeofunits6']; $typeofunits7=$_POST['typeofunits7']; $typeofunits8=$_POST['typeofunits8']; $unitdescription=$_POST['unitdescription']; $unitdescription2=$_POST['unitdescription2']; $unitdescription3=$_POST['unitdescription3']; $unitdescription4=$_POST['unitdescription4']; $unitdescription5=$_POST['unitdescription5']; $unitdescription6=$_POST['unitdescription6']; $unitdescription7=$_POST['unitdescription7']; $unitdescription8=$_POST['unitdescription8']; $unitmanufacturer=$_POST['unitmanufacturer']; $unitmanufacturer2=$_POST['unitmanufacturer2']; $unitmanufacturer3=$_POST['unitmanufacturer3']; $unitmanufacturer4=$_POST['unitmanufacturer4']; $unitmanufacturer5=$_POST['unitmanufacturer5']; $unitmanufacturer6=$_POST['unitmanufacturer6']; $unitmanufacturer7=$_POST['unitmanufacturer7']; $unitmanufacturer8=$_POST['unitmanufacturer8']; $modelnumber=$_POST['modelnumber']; $modelnumber2=$_POST['modelnumber2']; $modelnumber3=$_POST['modelnumber3']; $modelnumber4=$_POST['modelnumber4']; $modelnumber5=$_POST['modelnumber5']; $modelnumber6=$_POST['modelnumber6']; $modelnumber7=$_POST['modelnumber7']; $modelnumber8=$_POST['modelnumber8']; $serialnumber=$_POST['serialnumber']; $serialnumber2=$_POST['serialnumber2']; $serialnumber3=$_POST['serialnumber3']; $serialnumber4=$_POST['serialnumber4']; $serialnumber5=$_POST['serialnumber5']; $serialnumber6=$_POST['serialnumber6']; $serialnumber7=$_POST['serialnumber7']; $serialnumber8=$_POST['serialnumber8']; $coolingperiod=$_POST['coolingperiod']; $coolingperiod2=$_POST['coolingperiod2']; $coolingperiod3=$_POST['coolingperiod3']; $coolingperiod4=$_POST['coolingperiod4']; $coolingperiod5=$_POST['coolingperiod5']; $coolingperiod6=$_POST['coolingperiod6']; $coolingperiod7=$_POST['coolingperiod7']; $coolingperiod8=$_POST['coolingperiod8']; $refrigerationtype=$_POST['refrigerationtype']; $refrigerationtype2=$_POST['refrigerationtype']; $refrigerationtype3=$_POST['refrigerationtype3']; $refrigerationtype4=$_POST['refrigerationtype4']; $refrigerationtype5=$_POST['refrigerationtype5']; $refrigerationtype6=$_POST['refrigerationtype6']; $refrigerationtype7=$_POST['refrigerationtype7']; $refrigerationtype8=$_POST['refrigerationtype8']; $chilleroiltype=$_POST['chilleroiltype']; $chilleroiltype2=$_POST['chilleroiltype2']; $chilleroiltype3=$_POST['chilleroiltype3']; $chilleroiltype4=$_POST['chilleroiltype4']; $chilleroiltype5=$_POST['chilleroiltype5']; $chilleroiltype6=$_POST['chilleroiltype6']; $chilleroiltype7=$_POST['chilleroiltype7']; $chilleroiltype8=$_POST['chilleroiltype8']; $chilleroilcapacity=$_POST['chilleroilcapacity']; $chilleroilcapacity2=$_POST['chilleroilcapacity2']; $chilleroilcapacity3=$_POST['chilleroilcapacity3']; $chilleroilcapacity4=$_POST['chilleroilcapacity4']; $chilleroilcapacity5=$_POST['chilleroilcapacity5']; $chilleroilcapacity6=$_POST['chilleroilcapacity6']; $chilleroilcapacity7=$_POST['chilleroilcapacity7']; $chilleroilcapacity8=$_POST['chilleroilcapacity8']; $query ="INSERT INTO item(id,equipmentunits,company,companyAddress,contactname,contactphonenumber,contactmobilenumber,contactemail,equipmentunits,typeofunits,unitdescription,unitmanufacturer,modelnumber,serialnumber,coolingperiod,refrigerationtype, chilleroiltype, chilleroilcapacity) VALUES ('$id', '$company', '$companyAddress', '$contactname', '$contactphonenumber', '$contactmobilenumber', '$contactemail', ('','$equipmentunits', '$typeofunits', '$unitdescription','$unitmanufacturer','$modelnumber','$serialnumber','$coolingperiod','$refrigerationtype','$chilleroiltype''$chilleroilcapacity'), ('','$equipmentunits2', '$typeofunits2', '$unitdescription2','$unitmanufacturer2','$modelnumber2','$serialnumber','$coolingperiod2','$refrigerationtype2','$chilleroiltype2','$chilleroilcapacity2'), ('','$equipmentunits3', '$typeofunits3', '$unitdescription3','$unitmanufacturer3','$modelnumber3','$serialnumber3','$coolingperiod3','$refrigerationtype3','$chilleroiltype2''$chilleroilcapacity3'), ('','$equipmentunits4', '$typeofunits4', '$unitdescription4','$unitmanufacturer4','$modelnumber4','$serialnumber4','$coolingperiod4','$refrigerationtype4','$chilleroiltype2''$chilleroilcapacity4'), ('','$equipmentunits5', '$typeofunits5', '$unitdescription5','$unitmanufacturer5','$modelnumber5','$serialnumber5','$coolingperiod5','$refrigerationtype5','$chilleroiltype2''$chilleroilcapacity5'), ('','$equipmentunits6', '$typeofunits6', '$unitdescription6','$unitmanufacturer6','$modelnumber6','$serialnumber6','$coolingperiod6','$refrigerationtype6','$chilleroiltype2''$chilleroilcapacity6'), ('','$equipmentunits7', '$typeofunits7', '$unitdescription7','$unitmanufacturer7','$modelnumber7','$serialnumber7','$coolingperiod7','$refrigerationtype7','$chilleroiltype2''$chilleroilcapacity7'), ('','$equipmentunits8', '$typeofunits8', '$unitdescription8','$unitmanufacturer8','$modelnumber8','$serialnumber'8,'$coolingperiod8','$refrigerationtype8','$chilleroiltype2''$chilleroilcapacity8')"; mysql_query($query); if($query){ echo "Successful"; echo "
"; } else { echo "ERROR"; } // close connection mysql_close(); ?>[/php]

I fixed the html errors that I saw. as for the php part. I see what you’re trying to do, but you need to revise it or find some way to detecting how many units are being filled in so you don’t end up with a ton of empty row inserts. As tedious as it may seem, doing one at a time would be a lot easier and less time consuming to figure out. You could add a reset button to clear the current fields to simulate it moving to another row and also record the current stuff.

Sponsor our Newsletter | Privacy Policy | Terms of Service