Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    93
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Help needed for image upload using PHP

    Hi,

    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.

    thanks.

    Code:
    <?php
    $floor=$_REQUEST['floor']; 
    $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');
    	mysql_close();
       //Return the user to the location page
    	    header("Location:html_view_floors.php");
    	    exit;
    	}?>
    	<?php
    	}
    ?>
    <?php
    //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 
    }
    ?>
    <head>
    <title>Cam-Eye - Building - New</title>
    <link rel="stylesheet" href="zm_html_styles.css" type="text/css">
    </head>
    <body>
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
    <tr>
    <td align="left" class="head">Location - New Building</td>
    <td align="right" valign="bottom" class="text">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    <table border="0" cellspacing="0" cellpadding="4" width="100%">
    <tr>
    <td width="114" class="activetab">Add New Bulding</td>
    <td class="nontab">&nbsp;</td>
    </tr>
    </table>
    <table border="0" cellspacing="0" cellpadding="2" width="100%">
    <?php if (!empty($message)) {?>
    
                        <tr>
                            <td class="Text" colspan="2"><?php echo $message;?></td>
                        </tr>
    <?php } ?>
    <form name="building_form" method="post" action="<?php $PHP_SELF ?>">
    <input type="hidden" name="submit" value="1" >
    </br>						  
    <tr>
    <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>
    </tr>
    <tr></tr><tr></tr>
    <td align="left" class="text">Floor Name</td>
    <td align="left" class="text">
    <input class="inputfield" name="floor" id="floor" size="25" ></td>
    </tr>
    <tr></tr><tr></tr>
    <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>
    
    <tr><td colspan="2" align="left" 
    class="text">&nbsp;</td></tr>
    <tr style="height: 100%; vertical-align: bottom;">
    <td colspan="2" align="right">
    <input type="submit" value="Save" class="form">&nbsp;&nbsp;</td>
    </tr>
    
    </table>
    </FORM>
    </body>

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

    http://us3.php.net/manual/en/features.file-upload.php

    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
    •