Helo guys....I am very happy to intract with you all. can any one suggest me how to upload a image...i trie so many web site..here is my code..

uploadimage.php

 <?php
 define ("MAX_SIZE","10000"); 
 define ("WIDTH","150"); 
 define ("HEIGHT","100"); 
 function make_thumb($img_name,$filename,$new_w,$new_h)
 {
    $ext=getExtension($img_name);
    if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
        $src_img=imagecreatefromjpeg($img_name);

    if(!strcmp("png",$ext))
        $src_img=imagecreatefrompng($img_name);

    $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);

    $ratio1=$old_x/$new_w;
    $ratio2=$old_y/$new_h;
    if($ratio1>$ratio2) {
        $thumb_w=$new_w;
        $thumb_h=$old_y/$ratio1;
    }
    else    {
        $thumb_h=$new_h;
        $thumb_w=$old_x/$ratio2;
    }
    $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 

    if(!strcmp("png",$ext))
        imagepng($dst_img,$filename); 
    else
        imagejpeg($dst_img,$filename); 

    //destroys source and destination images. 
    imagedestroy($dst_img); 
    imagedestroy($src_img); 
 }

 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

 $errors=0;
 // checks if the form has been submitted
 if(isset($_POST['Submit']))
 {
 //reads the name of the file the user submitted for uploading
    $image=$_FILES['image']['name'];
    // if it is not empty
    if ($image) 
    {
        // get the original name of the file from the clients machine
        $filename = stripslashes($_FILES['image']['name']);

        // get the extension of the file in a lower case format
        $extension = getExtension($filename);
        $extension = strtolower($extension);
        if (($extension != "jpg")  && ($extension != "jpeg") && ($extension != "png"))  
        {
            echo '<h1>Unknown extension!</h1>';
            $errors=1;
        }
        else
        {
            $size=getimagesize($_FILES['image']['tmp_name']);
            $sizekb=filesize($_FILES['image']['tmp_name']);

            if ($sizekb > MAX_SIZE*1024)
            {
                echo '<h1>You have exceeded the size limit!</h1>';
                $errors=1;
            }

            $image_name=$filename.'.'.$extension;
            $newname="images/".$image_name;
            $copied = copy($_FILES['image']['tmp_name'], $newname);
            if (!$copied) 
            {
                echo '<h1>Copy unsuccessfull!</h1>';
                $errors=1;
            }
            else
            {
                $thumb_name='images/'.$image_name;
                $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
            }}  }}

  //If no errors registred, print the success message and show the thumbnail image created
 if(isset($_POST['Submit']) && !$errors) 
 {?>
<!-- echo "<h1>Thumbnail created Successfully!</h1>";--->
    <div style="display:inline; position:absolute; margin-left:900px; margin-top:130px"><?php echo '<img src="'.$thumb_name.'">';?></div>
<?php 
 }
 ?>

<script type="text/javascript" language="javascript">

//Checking Email Validations
function valid()
{
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   if(!document.form1.email.value.match(emailExp))
     {
  alert('Invalid Email Format');
  document.form1.email.focus();
  return false;
     }
}

//Checking for Validations
 function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);
    return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(cnd,"Name must be filled out!")==false)
  {cnd.focus();return false;}
  if (validate_required(sur,"Surname must be filled out!")==false)
  {sur.focus();return false;}
  if (validate_required(gender,"Gender must be filled out!")==false)
  {gender.focus();return false;}
    if (validate_required(Marital,"Marital Status must be filled out!")==false)
  {Marital.focus();return false;}
    if (validate_required(Caste,"Caste must be filled out!")==false)
  {Caste.focus();return false;}
  if (validate_required(Cat,"Category must be filled out!")==false)
  {Cat.focus();return false;}
    if (validate_required(Reg,"Religion must be filled out!")==false)
  {Reg.focus();return false;}
    if (validate_required(dob,"Date of Birth must be filled out!")==false)
  {dob.focus();return false;}
    if (validate_required(phstd,"Phone Number must be filled out!")==false)
  {phstd.focus();return false;}
    if (validate_required(mobno,"Mobile Number must be filled out!")==false)
  {mobno.focus();return false;}
    if (validate_required(email,"Email must be filled out!")==false)
  {email.focus();return false;}
    if (validate_required(address,"Addrese Premanent must be filled out!")==false)
  {address.focus();return false;}
    if (validate_required(addprs,"Present Address must be filled out!")==false)
  {addprs.focus();return false;}
    if (validate_required(refadd,"Reference Address must be filled out!")==false)
  {refadd.focus();return false;}
      if (validate_required(eduqlf,"Qualification must be filled out!")==false)
  {eduqlf.focus();return false;}
  if (validate_required(document.newad.image,"Image must be selected!")==false)
  {document.newad.image.focus();return false;}
  }
}

//Ceching For Only Digits
function checkIt(evt)
{
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    {
        alert("This field accepts numbers only !")
        return false
    }
    status = ""
    return true
}

function Clear()
 {
 form1.reset(); //will reset all the controls in ur page to initial stage.
  }
</script> 
 <body bgcolor="#000000">
 <form name="newad" method="post" enctype="multipart/form-data"  action="">
 <div style="display:inline; position:absolute; margin-left:870; margin-top:230"><table>
    <tr><td><input type="file" name="image" id="image"></td></tr>
    <tr><td><input name="Submit" type="submit" value="Upload image" ></td></tr>
 </table></div>
 </form>

 <form name="form1" method="POST" action="DB.php" enctype="multipart/form-data" onSubmit="return validate_form(this)">
<div align="center"><img src="AMG title copy.jpg"></div>
<table align="center" width="700" bgcolor="#CAFFFF" style="font-family:'Futura Bk'"  cellspacing="2">
<tr><td width="19">&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
<td width="218">1. Name of the Candidate :</td>
<td width="202"><input type="text" name="cnd"></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>2. Surname :</td><td><input type="text" name="sur"></td></tr>
<tr>
  <td>&nbsp;</td>
  <td>3. Gender :</td>
       <td><select name="gender" style="width:150px">
         <option style="font-size:9px; font-family:'Arial, Helvetica, sans-serif'; color:grey; font-style:italic" value="" selected>[Choose Yours]
         <option value="Male">Male</option>
         <option value="Female">Female</option>
       </select></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>4. Marital Status :</td>
  <td><select name="Marital" style="width:150px">
         <option style="font-size:9px; font-family:'Arial, Helvetica, sans-serif'; color:grey; font-style:italic" value="" selected>[Choose Yours]
         <option value="Single">Single</option>
         <option value="Married">Married</option>
         <option value="Divorced">Divorced</option>
         <option value="Widowed">Widowed</option>
       </select></td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td>5. Caste :</td>
        <td><select name="Caste" style="width:70px">
         <option style="font-size:9px; font-family:'Arial, Helvetica, sans-serif'; color:grey; font-style:italic" value="" selected>[Choose Yours]
          <option value="SC">SC</option>
          <option value="ST">ST</option>
          <option value="BC">BC</option>
          <option value="OC">OC</option>
        </select>
          <select name="Cat" style="width:72px">
         <option style="font-size:9px; font-family:'Arial, Helvetica, sans-serif'; color:grey; font-style:italic" value="" selected>[Choose Yours]
            <option value="A">A</option>
            <option value="B">B</option>
            <option value="C">C</option>
            <option value="D">D</option>
          </select></td>
</tr>    
<tr>
  <td>&nbsp;</td>
  <td>6. Religion :</td>
  <td><select name="Reg" style="width:150px">
         <option style="font-size:9px; font-family:'Arial, Helvetica, sans-serif'; color:grey; font-style:italic" value="" selected>[Choose Yours]
         <option value="Hinduism">Hinduism</option>
         <option value="Muslim">Muslim</option>
         <option value="Christianity">Christianity</option>
       </select>
       </td>
<tr><td>&nbsp;</td>
      <td>7. Date of Birth :</td>
  <td><input type="text" name="dob"></td></tr>
  <DIV style="DISPLAY: inline; FONT-SIZE: 8pt; Z-INDEX: 103; COLOR: gray; FONT-FAMILY: verdana; POSITION: absolute; margin-left:420px; top:308px ">Enter in YYYY/MM/DD format</DIV>
  <td>&nbsp;</td>
    <td>8. Phone No. (Res):</td>
  <td><input type="text" name="phstd" onKeyPress="return checkIt(event)"></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>9. Mobile No :</td>
  <td><input type="text" name="mobno" onKeyPress="return checkIt(event)"></td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td>10. Email ID :</td>
  <td><input type="text" name="email" onBlur="return valid(email)"></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>11. Address Permanent:</td>
  <td><textarea rows="5" cols="21" name="address" style="font-family:Arial, Helvetica, sans-serif'; font-size:15px"></textarea></td>
  <DIV style="DISPLAY: inline; FONT-SIZE: 12pt; Z-INDEX: 103; COLOR:black; FONT-FAMILY:'Futura Bk'; POSITION: absolute; margin-left:410px; top:440px ">Present</DIV>
  <td align="center"><textarea rows="5" cols="21" name="addprs" style="font-family:Arial, Helvetica, sans-serif'; font-size:15px"></textarea></td></tr>
<tr>
  <td>&nbsp;</td>
  <td style="font-family:'Futura Bk'">12. Reference Name<br /> 
    and Address :</td>
  <td><textarea rows="5" cols="21" name="refadd" style="font-family:Arial, Helvetica, sans-serif'; font-size:15px"></textarea></td>
  <td>&nbsp;</td></tr>
<tr>
  <td>&nbsp;</td>
  <td>13. Educational Qualification :</td>
  <td><input type="text" name="eduqlf"></td>
  <tr><td>&nbsp;</td></tr>
  <tr>
  <td>&nbsp;</td>
  <td align="center"><input type="submit" name="submit" value="Submit"/></td>
  <td align="center"><input type="button" value="Clear" onClick="Clear()"></td>
  <td align="center"><input type="button" value="Cancel" onClick="window.location='fields.html'"></td></tr>
</table>
</form>
</body>

Database file (DB.php):

<?php 
    //Connection Establish
    $con=mysql_connect("localhost","root","");
        if(!$con)
    {
        die ("Not Connected");
    }
/*      echo "<script language='javascript'>alert('Connected to the MYSQL')</script>";  */

    //Select Database
    mysql_select_db("data",$con);

$rand=rand(1, 10000); 
echo $rand;
echo "<script>alert('Your ID is $rand')</script>";

$img=$_GET['$newname'];
//Create Table
$crt="CREATE TABLE fields(SNo INT(5) NOT NULL AUTO_INCREMENT,PRIMARY KEY(SNo), YourID int(10), Name Varchar(15), Surname Varchar(15), Gender Varchar(15), DOB Date, Marital Varchar(20), Caste Varchar(10), Category Varchar(5), Religion Varchar(20), Phone int(10), Mobile BIGINT, Email Text, PrsAdd Text,  PerAdd Text, Reference Text, Education Varchar(5), Image Varchar(30))";
mysql_query($crt,$con);
/*  echo "<script language='javascript'>alert('Table Created')</script>"; */


//Insert Record
$ins="insert into fields(YourID, Name, Surname, Gender, DOB, Marital, Caste, Category, Religion, Phone, Mobile, Email, PrsAdd, PerAdd, Reference, Education, Image) Values('$rand','$_POST[cnd]','$_POST[sur]','$_POST[gender]','$_POST[dob]','$_POST[Marital]','$_POST[Caste]','$_POST[Cat]','$_POST[Reg]','$_POST[phstd]','$_POST[mobno]','$_POST[email]','$_POST[address]','$_POST[addprs]','$_POST[refadd]','$_POST[eduqlf]','$img')";
mysql_query($ins,$con);

echo "<script language='javascript'>alert('One Record Inserted')</script>";
echo "<script>alert('File Uploaded Successfully!.. Try Again!')</script>";
echo "<script language='javascript'>window.location='http://localhost/fields.html'</script>";

//Connection Closed
mysql_close($con);
//echo 'connection closed';
?>

Plz...check this file and can anyone solve my problem....thank you...

You have posted the entire code but not specified what problem you are facing. Please specify the problem, any error messages you are getting and at which locations. We should then be able to help.

haha

Thankyou for ur rply. i solved the problem....is there any tutorials for easy learnig AJAX...i would like to transefer my project into Ajax...so plz tell me is there anything...Bye.

well, just learn jquery, it makes ajax as simple as hell for you :)

or you can say, "jquery is javascript at its best" :)

I prefer Mootools over JQuery. Both are good though. For those who dont know what theasum and me are talking about JQuery (http://jquery.com/) and Mootools (http://mootools.net/) are javascript libraries. They are already built coding systems that make it easier to work with Javascript.

If you you want to use AJAX the hard way, check out the W3Schools tutorial at http://www.w3schools.com/ajax/default.asp.

All the best and Happy Learning!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.