Status
Not open for further replies.
type is not show i am submit form but show Arry is not type name


fT50rxG1cU7_pBfj0Vhw.png


Please check checkbox

Form Code:
PHP:
        <div class="toggle_container">
                        <div class="block">
                        
                        
                            <form enctype="multipart/form-data" action="add.php" method="POST">
                                <center><b><h7>Vendor Service Request</h7></b></center>
                                
                                <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                            <label class="hospitalname">Hospital Name</label>
                                            <div>
                                                <input type="text" name="hospname" class="long">
                                            </div>
                                        </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label>Ref No.</label>
                                            <div>
                                            
                                                <input type="text" name="refno" class="long">
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                                
                                 <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                            <label>From</label>
                                            <div>
                                                <input type="text" name="from" class="long">
                                            </div>
                                        </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label>Description</label>
                                            <div>
                                            
                                                <input type="text" name="description" class="long">
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                      
                                 <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                            <label>Designation</label>
                                            <div>
                                                <input type="text" name="designation" class="long">
                                            </div>
                                        </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label>Manufacture</label>
                                            <div>
                                            
                                                <input type="text" name="manufacture" class="long">
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                      
                                 <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                            <label>Tel Number</label>
                                            <div>
                                                <input type="text" name="telnumb" class="long">
                                            </div>
                                        </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label>Models</label>
                                            <div>
                                            
                                                <input type="text" name="models" class="long">
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                      
                                 <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                            <label>Mobile Number</label>
                                            <div>
                                                <input type="text" name="mobnumb" class="long">
                                            </div>
                                        </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label>Serial numbers</label>
                                            <div>
                                            
                                                <input type="text" name="serialnumb" class="long">
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                                
                                 <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                            <label>Fax</label>
                                            <div>
                                                <input type="text" name="fax" class="long">
                                            </div>
                                        </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label>Equipment</label>
                                            <div>
                                            
                                                <input type="text" name="equipment" class="long">
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                      
                                 <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                            <label>Email address</label>
                                            <div>
                                                <input type="text" name="emailadd" class="long">
                                            </div>
                                        </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label class="attachment">Attachement</label>
                                            <div>
                                            
                                                <input type="file" id="fileupload2" name="attachement" class="uniform">
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                                
                                <div class="columns clearfix">
                                    
                                    <div class="col_50">
                                        <fieldset>
                                    
                                    <label>Type</label>
                                    <div class="uniform">
                                        <label for="yes">
                                            <input type="checkbox" name="type[]" value="AG" id="yes"/>
                                            Warranty
                                        </label>
                                        <label for="no">
                                            <input type="checkbox" name="type[]" value="GE" id="no"/>
                                            PPM Contact
                                        </label>
                                        <label for="cant">
                                            <input type="checkbox" name="type[]" value="BR" id="no"/>
                                            Repair argent
                                        </label>
                                    
                                </fieldset>
                                    </div>
                                    
                                    <div class="col_50">
                                    
                                        <fieldset>
                                            
                                            <label>Fault Description And Service Description</label>
                                            <div>
                                            
                                                <textarea height="50px" name="faultdsd" class="long"></textarea>
                                            
                                            </div>
                                            
                                        </fieldset>
                                    
                                    </div>
                                    
                                </div>
                                
                                                   
                                <div class="padding_10">                                    
                                    
                                    <button type="submit" value="Add" class="button blue"> <img src="images/icons/white/png/checkmark_icon&16.png" /> Submit </button>
                                    <div class="clear"></div><!-- CLEAR BOTH -->
                                    
                                </div>

                            </form>
                            
                        </div>
                        
                    </div>
                    
                </div>


add.php
PHP:
 <?php 
 
 //This is the directory where images will be saved 
 $target = "vendor-req-service/"; 
 $target = $target . basename( $_FILES['attachement']['name']); 
 
 if(isset($_POST['type']))
{
foreach($_POST['type'] as $value) {
$insert="INSERT INTO type (type) VALUES ('$value')";
mysql_query($insert);
}
}
 
 //This gets all the other information from the form 
 $id=$_POST['ClientID']; 
 $hospname=$_POST['hospname']; 
 $refno=$_POST['refno']; 
 $from=$_POST['from']; 
 $description=$_POST['description']; 
 $designation=$_POST['designation']; 
 $manufacture=$_POST['manufacture']; 
 $telnumb=$_POST['telnumb']; 
 $models=$_POST['models']; 
 $mobnumb=$_POST['mobnumb']; 
 $serialnumb=$_POST['serialnumb']; 
 $fax=$_POST['fax']; 
 $equipment=$_POST['equipment']; 
 $emailadd=$_POST['emailadd'];
 $insert=$_POST['type']; 
 $faultdsd=$_POST['faultdsd']; 
 $pic=($_FILES['attachement']['name']);


 
 
 // Connects to your Database 
 mysql_connect("localhost", "username", "password") or die(mysql_error()) ; 
 mysql_select_db("my_db") or die(mysql_error()) ; 
 
 //Writes the information to the database 
 mysql_query("INSERT INTO `vendor` VALUES ('$id', '$hospname', '$refno', '$from', '$description', '$designation', '$manufacture', '$telnumb', '$models', '$mobnumb', '$serialnumb', '$fax', '$equipment', '$emailadd',  '$pic',  '$insert',  '$faultdsd')") ; 
 
 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['attachement']['tmp_name'], $target)) 
 { 
 
 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 
 
 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?>
 
Replace
PHP:
<label for="yes">
                                            <input type="checkbox" name="type[]" value="AG" id="yes"/>
                                            Warranty
                                        </label>
                                        <label for="no">
                                            <input type="checkbox" name="type[]" value="GE" id="no"/>
                                            PPM Contact
                                        </label>
                                        <label for="cant">
                                            <input type="checkbox" name="type[]" value="BR" id="no"/>
                                            Repair argent
                                        </label>
With
PHP:
                                        <label for="yes">
                                            <input type="checkbox" name="type" value="Warranty" id="yes">
                                            Warranty
                                        </label>
                                        <label for="no">
                                            <input type="checkbox" name="type" value="PPM Contact" id="no"/>
                                            PPM Contact
                                        </label>
                                        <label for="cant">
                                            <input type="checkbox" name="type" value="Repair argent" id="cant"/>
                                            Repair argent
                                        </label>
Change the values according to your requirement.

Edit: As for file download, replace in Full View Record Code:
PHP:
print ("<label class='hospitalname'>{$a_row['attachement']}</label>" );
With
PHP:
print ("<label class='hospitalname'><a href=\"vendor-req-service/{$a_row['attachement']}\">{$a_row['attachement']}</a></label>" );
You might need to change the absolute path according to your directory.
 
Last edited:
show this error

Warning: Invalid argument supplied for foreach() in G:\WampDeveloper\Websites\DefaultWebsite\webroot\test4\add.php on line 9 The file has been uploaded, and your information has been added to the directory

Line 9 is:
PHP:
foreach($_POST['type'] as $value) {

add.php code:
PHP:
 <?php 
 
 //This is the directory where images will be saved 
 $target = "vendor-req-service/"; 
 $target = $target . basename( $_FILES['attachement']['name']); 
 
 if(isset($_POST['type']))
{
foreach($_POST['type'] as $value) {
$insert="INSERT INTO type (type) VALUES ('$value')";
mysql_query($insert);
}
}
 
 //This gets all the other information from the form 
 $id=$_POST['ClientID']; 
 $hospname=$_POST['hospname']; 
 $refno=$_POST['refno']; 
 $from=$_POST['from']; 
 $description=$_POST['description']; 
 $designation=$_POST['designation']; 
 $manufacture=$_POST['manufacture']; 
 $telnumb=$_POST['telnumb']; 
 $models=$_POST['models']; 
 $mobnumb=$_POST['mobnumb']; 
 $serialnumb=$_POST['serialnumb']; 
 $fax=$_POST['fax']; 
 $equipment=$_POST['equipment']; 
 $emailadd=$_POST['emailadd'];
 $insert=$_POST['type']; 
 $faultdsd=$_POST['faultdsd']; 
 $pic=($_FILES['attachement']['name']);


 
 
 // Connects to your Database 
 mysql_connect("localhost", "zain", "pimsat") or die(mysql_error()) ; 
 mysql_select_db("zain") or die(mysql_error()) ; 
 
 //Writes the information to the database 
 mysql_query("INSERT INTO `vendor` VALUES ('$id', '$hospname', '$refno', '$from', '$description', '$designation', '$manufacture', '$telnumb', '$models', '$mobnumb', '$serialnumb', '$fax', '$equipment', '$emailadd',  '$pic',  '$insert',  '$faultdsd')") ; 
 
 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['attachement']['tmp_name'], $target)) 
 { 
 
 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 
 
 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?>
 
change
PHP:
if(isset($_POST['type']))
to
PHP:
if(is_array($_POST['type']))

If it doesn't show anything $_POST['type'] is not an array used in a foreach....
 
Status
Not open for further replies.
Back
Top