FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need Serious help !!!!!! plzzzz





salman_500
well guyz.... i dunno what rong here... but its seriously has driven me crazy... i checked a 100 times.. and i can find no error.... but therei definetly is coz the script aint working how it should...

Note : if its just a silly mistake.. plz dont make fun of me ... Shocked im stressed out ! Razz

ok here is my form :

Code:
<form enctype="multipart/form-data" name="post" method="POST">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="25%" align="left" valign="top">Name:</td>
      <td width="75%" align="left" valign="top"><input name="name" style="background-image:url(Templates/Urbane/images/forms/image_10.gif); border-width:1px; border-color:#B39B9B; border-style:solid"/></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top">Category:</td>
      <td align="left" valign="top"><label>
        <select name="category" id="category" class="select">
      <?php
      $getcats = mysql_query("SELECT * FROM scripts_cat ORDER BY 'name' ASC");
            while ($categories = MySQL_Fetch_Array($getcats)) {
    echo ("<option value=\"$categories[name]\" >$categories[name]</option>");
} ?>
        </select>
        </label></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top">Description:</td>
      <td align="left" valign="top"><textarea name="description" class="forumheadbar" style="background:#3F706A"></textarea></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top"></td>
    </tr>
    <tr>
      <td align="left" valign="top">Author : </td>
      <td align="left" valign="top"><input name="author" style="background-image:url(Templates/Urbane/images/forms/image_10.gif); border-width:1px; border-color:#B39B9B; border-style:solid" id="author"/></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top">Image:</td>
      <td align="left" valign="top"><input name="img" type="file" style="background-image:url(Templates/Urbane/images/forms/image_10.gif); border-width:1px; border-color:#B39B9B; border-style:solid"/></td>
    </tr>
    <tr>
      <td height="24" align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top">File:</td>
      <td align="left" valign="top"><input name="file" type="file" style="background-image:url(Templates/Urbane/images/forms/image_10.gif); border-width:1px; border-color:#B39B9B; border-style:solid"/></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top"></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top"><input name="submit" type="submit" value="Submit" /></td>
    </tr>
  </table>
 
</form>



and here is the script :

Code:
if ($_POST['submit']){

function randomid() {
  $salt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  srand((double)time()*1000000); 
      $i = 0;
      while ($i <= 5) {
            $num = rand() % 33;
            $tmp = substr($salt, $num, 1);
            $randid = $randid . $tmp;
            $i++;
      }
      return $randid;
}

$id = randomid();
$name = ucfirst("".$_POST['name']."");
$category = ucfirst("".$_POST['category']."");
$description = ucfirst("".$_POST['description']."");
$author = ucfirst("".$_POST['author']."");
$time = time();

$maxfilesize = 100000;
if (isset($_POST['img'])) {
// check if there was a file uploaded
if (!is_uploaded_file($_FILES['img']['tmp_name'])) {
    echo "<b>you didn't select a file to upload.</b><br />";
   // if it was, go ahead with other checks
} else {
    if ($_FILES['img']['size'] > $maxfilesize) {
        echo "<b>your image file was too large.</b><br />";
        unlink($_FILES['img']['tmp_name']);
    } else {
        $ext = strrchr($_FILES['img']['name'], ".");
        if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG") {
            echo "your file was an unacceptable type.<br />";
            unlink($_FILES['img']['tmp_name']);
        // if it's there, an okay size and type, copy to server and update the photo value in SQL
        } else {
             
           $imagename1 = $id.$ext;
           move_uploaded_file($_FILES['img']['tmp_name'],"modules/scripts/images/".$imagename1);
                   
       }
   }


// The file
$imagename = 'modules/scripts/images/'.$imagename1;
$extension = substr($imagename, strrpos($imagename, '.') + 1);

// Set a maximum height and width
$width = 60;
$height = 60;

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($imagename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
switch ($extension) {
  case 'gif': $image = imagecreatefromgif($imagename); break;
  case 'jpg': $image = imagecreatefromjpeg($imagename); break;
  case 'jpeg': $image = imagecreatefromjpeg($imagename); break;
  case 'png': $image = imagecreatefrompng($imagename); break;
  default: exit(''.$extension.''); break;
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
switch ($extension) {
  case 'gif': imagegif($image_p, 'modules/scripts/images/'. $id .'.'. $extension .''); break;
  case 'jpg': imagejpeg($image_p, 'modules/scripts/images/'. $id .'.'. $extension .''); break;
  case 'jpeg': imagejpeg($image_p, 'modules/scripts/images/'. $id .'.'. $extension .''); break;
  case 'png': imagepng($image_p, 'modules/scripts/images/'. $id .'.'. $extension .''); break;
  default: exit('Invalid extension.'); break;
}
}
}
else {
$getcatimg = mysql_query("SELECT img FROM scripts_cat WHERE name='$category'");
$catimg = mysql_fetch_array($getcatimg);
$imagename1 = "category/". $catimg['img'];
}

if (isset($_POST['file'])) {
// check if there was a file uploaded
if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
    $error2 = "<b>you didn't select a file to upload.</b><br />";
// if it was, go ahead with other checks
} else {
    if ($_FILES['file']['size'] > $maxfilesize) {
        $error2 = "<b>your file was too large.</b><br />";
        unlink($_FILES['file']['tmp_name']);
    } else {
        $ext3 = strrchr($_FILES['file']['name'], ".");
        if ($ext3 != ".zip" AND $ext3 != ".rar" AND $ext3 != ".ZIP" AND $ext3 != ".RAR") {
            $error2 = "your file was an unacceptable type.<br />";
            unlink($_FILES['file']['tmp_name']);
        // if it's there, an okay size and type, copy to server and update the photo value in SQL
        } else {
             
           $filename = $id.$ext3;
           move_uploaded_file($_FILES['file']['tmp_name'],"modules/scripts/files/".$filename);
                       
       }
   }
}
}

mysql_query("INSERT INTO scripts (id, name, category, description, author, addition_date, image, file) VALUES ('$id', '$name', '$category', '$description', '$author', '$time', '$imagename1', '$filename')") or die (mysql_error());

echo " Script Successfully added !<br><br>";
}
else {
include('addnew.htm');
}


the problem is .... when i submit the form.... the image is not passed on... niether is the file..

ok about the image thing...

i have made it so that the image is passed to the forum if the user submits its... and then checks it and does stuff with it ... but if the user does not submit the image... then the category image is used instead ....

but... no matter what i put in the image field.... it only submits in the databse the category image value !!

plz help !!!
mathiaus
line 26 of php code, change $_POST['img'] to $_FILES['img']
line 93 of php code, change $_POST['file'] to $_FILES['file']
They show up under $_FILES rather than post so your if statements meant they were being skipped because what you were checking for didn't exist.
salman_500
HOLY !!

Your a life savor !!!!! Very Happy

thnx !!
mathiaus
salman_500 wrote:
HOLY !!

Your a life savor !!!!! Very Happy

thnx !!

And don't I know it Razz
-close-
Related topics
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.