Results 1 to 5 of 5
  1. #1

    Exclamation Very urgent plz. Help..


    hello guyz,..magpa help lng ko about sa akong ghimo na site,..php akong gigamit sa site,ug may connection sya sa image..Ok na ang uploader sa akong site ug ma-view na kni after ma-save pero may big problem ko coz if ang user gusto nya mag change another picture dra na nag sugod ang problem nko mag consumed man gud sad sya ug laing field sa akong database tpus the same file name..


    mao ni akong source code


    <?php
    session_start();
    include 'dbcon.php';
    $email=$_SESSION['user'];

    $iquery="SELECT image FROM tbl_client WHERE email='$email'";
    $iresult=mysql_query($iquery) or die ("ERROR ME");



    function is_valid_type($file)
    {
    // This is an array that holds all the valid image types
    $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif");

    if (in_array($file['type'], $valid_types))
    return 1;
    return 0;

    }


    $TARGET_PATH = "upload/";
    $image = $_FILES['image'];
    $email=$_POST['email'];
    $image['name'] = mysql_real_escape_string($image['name']);
    $TARGET_PATH .= $image['name'];

    if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))
    {

    $sql = "insert into tbl_client values (id, '" . $image['name'] . "', '$email')";
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());

    ?>
    <script type="text/javascript">
    alert("YOU HAVE BEEN UPLOADED YOUR PICTURE");

    </script>
    <?php


    }

    if(file_exists($TARGET_PATH))
    {
    move_uploaded_file($image['tmp_name'], $TARGET_PATH);
    }



    }

    ?>




    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>

    <style type="text/css">
    <!--
    #form1 table tr td table tr td div a {
    color: #000;
    }
    -->
    </style>
    </head>

    <center><body background="Images/Background.gif">
    <form id="form1" name="form1" method="post" action="" enctype="multipart/form-data" >
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td height="437" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="19%" height="71">&nbsp;</td>
    <td width="57%">&nbsp;</td>
    <td width="24%">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height="39">&nbsp;</td>
    <td><div align="center"><a href="membermain.php?email=<?php echo $_GET['email'];?>">HOME</a> | PROFILE | <a href="barangayclearance.php?email=<?php echo $_GET['email'];?>">BARANGAY CLEARANCE</a> | <a href="contactusmember.php?email=<?php echo $_GET['email'];?>">CONTACT US</a></div></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="20%" height="318">&nbsp;</td>
    <td width="40%" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td colspan="2" align="left"><strong>UPLOAD IMAGE HERE
    <label></label>
    <label></label>
    <label></label>
    <input name="email" type="text" id="email" size="30" readonly="readonly" value="<?php echo $_GET['email']; ?>" />
    </strong></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="file" name="image" id="image" /> &nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input name="MAX_FILE_SIZE" type="hidden" id="key" value="100000" /> <input name="submit" type="submit" id="submit" value="UPLOAD" /> <input name="submit1" type="reset" id="submit1" value="CANCEL" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td colspan="2">Note: If you have already uploaded a picture before, we advised that you need to delete the previous picture because it is a government site or else we will delete your account.</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td width="29%">&nbsp;</td>
    <td width="71%">&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table></td>
    <td width="21%" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <?php
    while($row=mysql_fetch_array($iresult,MYSQL_BOTH))
    {
    ?>
    <td><strong>Welcome:</strong></td>
    <td rowspan="4" align="center" valign="top"><img src="upload/<?php echo $row['image'];?>" width="102" height="93" /></td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td width="29%"><h5 align="center">&nbsp;</h5></td>
    <td width="71%"><div align="center"><?php echo $_GET['email'];?></div></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><h5 align="center"><strong><a href="log-out.php">LOG-OUT</a></strong></h5></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td align="center"><h5><strong>Delete Photo</strong></h5></td>
    </tr>
    <tr>
    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td align="center">&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table></td>
    <td width="19%">&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table>


    </form>
    </body>
    </html>

  2. #2
    @TS:

    I wonder why you made it to insert a new record when uploading a new picture. I think you just have to update the "image" field of the record of that client instead of creating a new record.

    Also, add a script to check if the file exist or not and change its filename so it won't overwrite an existing image file. You may use while(file_exists($newimagefilename)).... so it loops again if the new filename does still exists.

  3. #3
    sakto c shadowchest bai, ang query nmu ky INSERT mn, change to UPDATE lng ...

  4. #4
    tnx for d advice mga bro..I try to make some codes na pang update lng but the question is..what if ang user una plang mu-upload ug pic.??..I solved that problem earlier some sort of conditioning if null then ->INSERT but if exist -> UPDATE..

    ----CODE----

    <?php
    session_start();
    include 'dbcon.php';
    $email=$_SESSION['user'];

    if(isset($_POST['key']))
    {
    function is_valid_type($file)
    {

    $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif");

    if (in_array($file['type'], $valid_types))
    return 1;
    return 0;

    }



    $TARGET_PATH = "upload/";
    $image = $_FILES['image'];
    $email=$_POST['email'];
    $image['name'] = mysql_real_escape_string($image['name']);
    $TARGET_PATH .= $image['name'];


    if (!is_valid_type($image))
    {

    die ("You must upload a jpeg, gif, or bmp");
    header("Location: upload.php?email=".$email);

    }


    move_uploaded_file($image['tmp_name'], $TARGET_PATH);

    $query="SELECT * FROM `tbl_client` WHERE `email`='$email'";
    $result=mysql_query($query);
    $num=mysql_num_rows($result);
    mysql_free_result($result);

    if($num!='0')
    {
    $sql = "UPDATE `tbl_client` SET image='".$image['name']."' WHERE email='$email'";
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
    }
    else
    {
    $sql = "INSERT INTO `tbl_client` VALUES(id, '".$image['name']."', '$email')";
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
    }


    ?>
    <script type="text/javascript">
    alert("YOU HAVE BEEN UPLOADED YOUR PICTURE");

    </script>


    <?php
    ----END---


    tnx sa advice mga bro.,Next time na sad..

  5. #5
    nice bro...

  6.    Advertisement

Similar Threads

 
  1. Replies: 2
    Last Post: 05-14-2011, 05:48 AM
  2. Looking For: fairy wings - color blue:very urgent:to be used tonight!help!
    By laura in forum Clothing & Accessories
    Replies: 3
    Last Post: 12-19-2009, 02:34 PM
  3. NEED HELP!!!! VERY URGENT
    By patricktan in forum Computer Hardware
    Replies: 24
    Last Post: 03-03-2008, 02:52 PM
  4. Burning Audio CD problem plz help.
    By ampdeck in forum Computer Hardware
    Replies: 31
    Last Post: 01-06-2008, 11:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top