1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Please help me removing this required field

Discussion in 'Programming' started by Divvy, Mar 21, 2011.

  1. #1
    hi friends,

    can someone help me? :)
    In my adminpanel, I have an page to edit my posts.
    here is an screenshot:
    [​IMG]

    The problem is that, If I want to change the date values only, I cant do It, because appears the error "Please select a Thumbnail Picture first".

    Can you please help me fix that? So I can change the date without sending a new thumbnail? I dont have any php knowledge :(

    Here goes my page code:
    <?
        ini_set("register_globals", 1);
        ini_set("session.bug_compat_42", "Off");
        ini_set("session.bug_compat_warn", "Off");
        session_start();
        if(!empty($_SESSION['login_status']))
        {
            include("../lib/globals.php");
            $dbc=mysql_connect($host,$username,$password) or die('Unable to connect to the database...');
            mysql_select_db($dbname) or die('Unable to select the database...');
    
            $id=(isset($_REQUEST['id']))?$_REQUEST['id']:0;
            $s=$_REQUEST['s'];
            
            $query="select * from thon_post where id='$id'";
            $result=mysql_query($query);
            if($result)
            {
                $r=mysql_fetch_array($result);
                
                $str_dt=$r['start_date'];
                $arr=explode('-',$str_dt);
                $str_dt1=date('j-M-Y',mktime(0,0,0,$arr[1],$arr[2],$arr[0]));
                
                $path="../uploaded/".$r['picture'];
                $currentimagesize=getimagesize($path);
                $image_width=$currentimagesize[0];
                $image_height=$currentimagesize[1];
                
                if(($image_height>117.63) || ($image_width>140))
                {
                    if($image_height>117.63)
                    {
                        $f1=(double)(117.63/$image_height);
                        $width=$image_width*$f1;
                        $height=117.63;
                    }
                    if($image_width>140)
                    {
                        $f2=(double)(140/$image_width);
                        $height=$image_height*$f2;
                        $width=140;
                    }
                }
                else
                {
                    $width=$image_width;
                    $height=$image_height;
                }
            }
            
            if(isset($_POST['submit']))
            {
                $st_dt=$_POST['start_date'];
                if($st_dt!='')
                {
                
                $arr=explode('-',$st_dt);
                if($arr[0]<10)
                {
                    $day='0'.$arr[0];
                }
                else
                {
                    $day=$arr[0];
                }
                switch($arr[1])
                {
                    case 'Jan':
                        $mon='01';
                        break;
                    case 'Feb':
                        $mon='02';
                        break;
                    case 'Mar':
                        $mon='03';
                        break;
                    case 'Apr':
                        $mon='04';
                        break;
                    case 'May':
                        $mon='05';
                        break;
                    case 'Jun':
                        $mon='06';
                        break;
                    case 'Jul':
                        $mon='07';
                        break;
                    case 'Aug':
                        $mon='08';
                        break;
                    case 'Sep':
                        $mon='09';
                        break;
                    case 'Oct':
                        $mon='10';
                        break;
                    case 'Nov':
                        $mon='11';
                        break;
                    case 'Dec':
                        $mon='12';
                        break;
                }
                
                $start_date=$arr[2]."-".$mon."-".$day;
                
                }
                else
                {
                
                $start_date=date('Y-m-d');
                
                }
    
                $thumb_pic=$_FILES['thumb_pic']['name'];
                $arr1=explode('.',$thumb_pic);
                $img1=date('ymdhis')."t.".$arr1[1];
                $dest1="../uploaded/".$img1;
                $val1_1=move_uploaded_file($_FILES['thumb_pic']['tmp_name'],$dest1);
                $qry="update thon_post set `picture_thumb`='$img1', `start_date`='$start_date' where id='$id'";
                $rs=mysql_query($qry);
                if($rs)
                {
    ?>
                    <script language="javascript" type="text/javascript">
                        alert("Post information successfully updated.");
                        window.location.href='display_post1.php?s=<? echo $s; ?>'; 
                    </script>
    <?
                }
            }                    
    ?>        
    <html>
    <head>
    <title>Thongsaroundtheworld Admin Area</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/javascript" src="../validator/datetimepicker.js"></script>
    <link href="../style/style.css" rel="stylesheet" type="text/css">
    <script language="javascript">
    function validate()
    {
        var thumb_pic=document.getElementById('thumb_pic').value;
        if(thumb_pic=='')
        {
            alert('Please select a Thumbnail Picture first.');
            document.f1.thumb_pic.focus();
            return false;
        }
        var ext=thumb_pic.substr(thumb_pic.lastIndexOf(".")).toLowerCase();
        if(ext != ".gif" && ext != ".jpeg" && ext != ".png" && ext != ".jpg") 
        {
            alert("Please select only JPG or GIF or PNG Thumbnail Picture.");
            document.f1.thumb_pic.focus();
            return false;
        }
    }
    </script>
    </head>
    <body leftmargin="0" topmargin="0">
    <? include("admin_header.php"); ?>
    <table align="center" width="100%" cellspacing="0" cellpadding="0" border="0" height="100%">
    <tr>
    <td width="175" align="left" valign="top" bgcolor="#eeeeee"><? include("left.php"); ?></td>
    <td align="center" valign="top">
    <br><br><br>
    <form name="f1" method="post" action="edit_post1.php?id=<? echo $id; ?>&s=<? echo $s; ?>" enctype="multipart/form-data" onSubmit="return validate();">
    <table border="0" cellpadding="0" cellspacing="4" align="center"><tr><td valign="top">
    <table width="360" cellspacing="0" cellpadding="0" align="center" class="tab_sty1">
      <tr bgcolor="#631e5c" height="18">
        <td align="center" class="mysty1" colspan="4"><font color="#FFFFFF"><b>Edit Post</b></font></td>
      </tr>
      <tr height="10"><td colspan="4"></td></tr>
        <tr height="22"><td width="16"></td><td width="120" class="mysty1">Name</td><td width="12" class="mysty1"><b>:</b></td><td width="210" class="mysty1"><? echo $r['name']; ?></td></tr>
        <tr height="22"><td width="16"></td><td width="120" class="mysty1">Country Name</td><td width="12" class="mysty1"><b>:</b></td><td width="210" class="mysty1"><? echo $r['country_name']; ?></td></tr>
        <tr height="22"><td width="16"></td><td width="120" class="mysty1">E-mail</td><td width="12" class="mysty1"><b>:</b></td><td width="210" class="mysty1"><? echo $r['email']; ?></td></tr>
        <tr height="22"><td width="16"></td><td width="120" class="mysty1">Comment</td>
        <td width="22" class="mysty1"><b>:</b></td><td width="210" class="mysty1"><? echo $r['comment']; ?></td></tr>
        <tr height="22"><td width="16"></td><td width="120" class="mysty1">Thumbnail Picture</td><td width="12" class="mysty1"><b>:</b></td><td width="210" class="mysty1"><input type="file" name="thumb_pic" id="thumb_pic" size="20"></td></tr>
        <tr height="22"><td width="16"></td><td width="120" class="mysty1">Start Date</td><td width="12" class="mysty1"><b>:</b></td><td class="mysty1"><input name="start_date" id="start_date" type="text" size="15" value="<? echo $str_dt1; ?>" readonly=""> 
        <a href="javascript:NewCal('start_date','ddmmmyyyy',false,24)"><img src="../images/cal.gif" alt="Pick a date" width="16" height="16" border="0" align="absmiddle"></a> (Optional)</td></tr>
        <tr height="10"><td colspan="4"></td></tr>
          <tr height="18"><td align="center" colspan="4"><input name="submit" type="submit" value="Submit"></td></tr>
          <tr height="10"><td colspan="4"></td></tr>
    </table>
    </td><td valign="top">
    <table width="148" border="0" cellpadding="0" cellspacing="0" align="center" class="tab_sty1">
    <tr height="18"><td align="center" bgcolor="#631e5c"><span class="mysty1"><font color="#FFFFFF"><b>Existing Picture</b></font></span></td></tr>
    <tr><td align="center" style="padding: 6px 6px 6px 6px;"><img src="<? echo $path; ?>" width="<? echo $width; ?>" height="<? echo $height; ?>"></td></tr>
    </table>
    <?
        if($r['picture_thumb']!='')
        {
            $path1="../uploaded/".$r['picture_thumb'];
    ?>    
    <br>
    <table width="148" border="0" cellpadding="0" cellspacing="0" align="center" class="tab_sty1">
    <tr height="18"><td align="center" bgcolor="#631e5c"><span class="mysty1"><font color="#FFFFFF"><b>Thumbnail Picture</b></font></span></td></tr>
    <tr><td align="center" style="padding: 6px 6px 6px 6px;"><img src="<? echo $path1; ?>" width="88" height="88" border="1"></td></tr>
    </table>
    <?
        }
    ?>
    </td>
    </tr>
    </table>
    </form>
    </td>
    </td>
    </tr>
    </table>
    </body>
    </html>
    <?
        }
        else
        {
            header("Location: index.php");
        }
    ?>
    PHP:
    I really appreciate If someone can help me :)
    Thank you!
     
    Divvy, Mar 21, 2011 IP
  2. imocoder

    imocoder Member

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    First you need to remove the javascript validation:
    
    onSubmit="return validate();"
    
    Code (markup):
    After that you need to change the PHP code so when thumbnail is not posted the database not to be updated.
     
    imocoder, Mar 22, 2011 IP
  3. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    I dont have php knowledge to fix that... can you or someone help me please? :)
     
    Divvy, Mar 22, 2011 IP