Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2005
    Thanked 0 Times in 0 Posts

    Help needed for image upload using PHP


    I have this form for adding a new location.

    It works fine. now i want to integrate jpeg image upload field along with this form.My form will have two buttons browse and submit.

    Can anyone help me to modify this to handle image upload.


    $building = $_REQUEST['building']; 
    $submit = $_REQUEST['submit'];
    //echo $building;
    //echo $floor;
    //Check if form has been submitted
    if ($submit==1){
    	//set variables of from form
    	$building = $_REQUEST['building'];
    		//Error check
    	if (empty($building)){
    		$message.="The building name is required.<br/>";
    	if (empty($floor)){
    		$message.="The floor name is required.<br/>";
    	//If the are no errors, insert the data to the database.
    	if (empty($message)){
    		$con = mysql_connect('test', 'user', 'pass');
    	mysql_select_db("test", $con);
    	//SQL to insert new building
    	$query = "INSERT INTO floors (Name,buildingId) VALUES ('$floor','$building')";
    	mysql_query($query) or die('Error, insert query failed');
       //Return the user to the location page
    //function to load Building Dropdown.
    function dropdown()
    // open connection 
    $con = mysql_connect('', 'user', 'pass');
    // select database 
    mysql_select_db("", $con);
    //this code is bringing in the values for the dropdown. 
    $query="select buildingId,Name from buildings order by Name"; 
    /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ 
    $result = mysql_query ($query); 
    while($row=mysql_fetch_array($result)){//Array or records stored 
    echo "<option value=$row[buildingId]>$row[Name]</option>"; 
    /* Option values are added by looping through the array */ 
    echo "</select>";// Closing of list box 
    <title>Cam-Eye - Building - New</title>
    <link rel="stylesheet" href="zm_html_styles.css" type="text/css">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
    <td align="left" class="head">Location - New Building</td>
    <td align="right" valign="bottom" class="text">&nbsp;</td>
    <table border="0" cellspacing="0" cellpadding="4" width="100%">
    <td width="114" class="activetab">Add New Bulding</td>
    <td class="nontab">&nbsp;</td>
    <table border="0" cellspacing="0" cellpadding="2" width="100%">
    <?php if (!empty($message)) {?>
                            <td class="Text" colspan="2"><?php echo $message;?></td>
    <?php } ?>
    <form name="building_form" method="post" action="<?php $PHP_SELF ?>">
    <input type="hidden" name="submit" value="1" >
    <td align="left" class="text">Building Name</td>
    <td align="left" class="text">
    <select class="inputfield" name="building" id="building" >
        <option value="">Select Building<?php echo dropdown();?> </td>
    <td align="left" class="text">Floor Name</td>
    <td align="left" class="text">
    <input class="inputfield" name="floor" id="floor" size="25" ></td>
    <td align="left" class="text">Floor Map</td>
    <td align="left" class="text">
    <input type="file" class="file" name="userfile" id="userfile" size="25" ></td>
    <tr><td colspan="2" align="left" 
    <tr style="height: 100%; vertical-align: bottom;">
    <td colspan="2" align="right">
    <input type="submit" value="Save" class="form">&nbsp;&nbsp;</td>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Thanked 637 Times in 625 Posts
    Start here:


    Examples and explanations abound.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts