Can someone check this script plz

Status
Not open for further replies.

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
I have got it so it posts into the table 'images' but I am struggling to get it to post into the table 'Post'
PHP:
<?php
define ('MAX_FILE_SIZE', 15000 * 50);
if (array_key_exists('upload', $_POST)) {
$n = rand(0, 100);
$rand = $_SESSION['id']*3+1-4+100-$n*8;
$rand1 = $_SESSION['id']*7-4+100-$n*8;
  define('UPLOAD_DIR', "avatars/$id/");
  $_FILES['image']['name'] = $rand.$rand1.$_FILES['image']['name'];
  $file = str_replace(' ', '_', $_FILES['image']['name']);
  $permitted = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png');
  if (in_array($_FILES['image']['type'], $permitted)
      && $_FILES['image']['size'] > 0
      && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
    switch($_FILES['image']['error']) {
      case 0:
        if (!file_exists(UPLOAD_DIR . $file)) {
        $file = str_replace(")", '', $file);
        $file = str_replace("(", '', $file);
          $success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR . $file);
          $query = mysql_query("SELECT * FROM `images` WHERE `myid`='".$_SESSION['id']."' LIMIT 1");
          $line = mysql_num_rows($query);
        mysql_query("INSERT INTO `images` (`myid`,`name`, `path`) VALUES ('".$_SESSION['id']."','".$_POST['name']."', '".UPLOAD_DIR . $file."')");
        mysql_query("INSERT INTO `post` (`myid`, `path`) VALUES ('".$_SESSION['id']."', '".UPLOAD_DIR . $file."')");
        mysql_free_result($query);
        } else {
          $result = 'A file of the same name already exists.';
        }
        if (isset($success)) {
          $result = "$file uploaded successfully.";
        } else {
          $result = "Error uploading $file. Please try again.";
        }
        break;
      case 3:
      case 6:
      case 7:
      case 8:
        $result = "Error uploading $file. Please try again.";
        break;
      case 4:
        $result = "You didn't select a file to be uploaded.";
    }
  } else {
    $result = "$file is either too big or not an image.";
  }
}
 
?>
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
What is the exact error it gives?

To find that out, replace
PHP:
mysql_query("INSERT INTO `post` (`myid`, `path`) VALUES ('".$_SESSION['id']."', '".UPLOAD_DIR . $file."')");

with

PHP:
mysql_query("INSERT INTO `post` (`myid`, `path`) VALUES ('".$_SESSION['id']."', '".UPLOAD_DIR . $file."')") or die(mysql_error());
 

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
What is the exact error it gives?

To find that out, replace
PHP:
mysql_query("INSERT INTO `post` (`myid`, `path`) VALUES ('".$_SESSION['id']."', '".UPLOAD_DIR . $file."')");

with

PHP:
mysql_query("INSERT INTO `post` (`myid`, `path`) VALUES ('".$_SESSION['id']."', '".UPLOAD_DIR . $file."')") or die(mysql_error());
It is not outputting any errors, but it is not going into post in the database
 

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
Echoing the data should have nothing to do with the MySQL query..
Yea i know, I figured out what was wrong I just needed to echo out the data properly coz i have in the posts table it has Text and path and i want it to show the <li> for the text being posted and a seperate <li> for the images being uploaded, Can u help me echo it properly please this is what it looks like now and it just sometimes shows the image uploaded and sometimes shows the text posted and its so annoying lol
PHP:
<?php
$query = mysql_query("SELECT * FROM `post` WHERE `myid`='".$_SESSION['id']."' ORDER BY `id` DESC");
$v = 0;
while($line = mysql_fetch_array($query)){
$result = mysql_query("SELECT * FROM `usersystem` WHERE `id`='".$line['myid']."' LIMIT 1");
$them = mysql_fetch_array($result);
$image = mysql_fetch_array($query);
$line['text'] = strip_tags($line['text']);
$img = $image['path'];
$v ++;
echo "
<li>
<div class=\"posts\">
<div class=\"delete\">Delete</div><img src=\"../images/profile/postedwall.png\" class=\"postwallimg\" /><img src=\"../images/profile/arrow-1.png\" class=\"nothinghere-arrow\" style=\"z-index:1;\"/>
<div class=\"top\"><img src='avatars/$id/".$them['profile_picture']."' class=\"profile-picture-small\" width='40px' height='40px' /> <i style=\"position:absolute; margin:23px 0px; font-weight:bold; color:#909090 ;\">".$them['first_name']." ".$them['last_name']."</i></div>
<div class=\"middle\">
 
<span class=\"textinside\">".substr($line['text'], 0, 150).(substr($line['text'], 0, 150) != $line['text'] ? "<a href=\"#\" class=\"see\">See More...</a>" : "")."</span>
</div>
<div class=\"bottom\"><img src=\"../images/profile/comment.png\" class=\"Commentz\" ex-id=\"".$v."\"/> <span class=\"commenttext\">No Comments</span> <img src=\"../images/profile/comment.png\" class=\"Likez\" style=\"margin-left:205px;\" /> <span class=\"commenttext\">No Likes </span></div>
<input type=\"text\" class=\"comment_box cb_".$v."\">
</li>";
if (($img) == ''){} else {
echo "
<li>
<div class=\"posts\"><img src=\"../images/profile/postedwall.png\" class=\"postwallimg\" /><img src=\"../images/profile/arrow-1.png\" class=\"nothinghere-arrow\" style=\"z-index:1;\"/>
<div class=\"top\"><img src='avatars/$id/".$them['profile_picture']."' class=\"profile-picture-small\" width='40px' height='40px' /> <i style=\"position:absolute; margin:23px 0px; font-weight:bold; color:#909090 ;\">".$them['first_name']." ".$them['last_name']."</i></div>
<div class=\"middle\">
<img src=\"".$image['path']."\" width=\"100%\" height=\"400px\" />
</div>
<div class=\"bottom\"><img src=\"../images/profile/comment.png\" class=\"Commentz\" ex-id=\"".$v."\"/> <span class=\"commenttext\">No Comments</span> <img src=\"../images/profile/comment.png\" class=\"Likez\" style=\"margin-left:205px;\" /> <span class=\"commenttext\">No Likes </span></div>
<input type=\"text\" class=\"comment_box cb_".$v."\">
</li>
";
}
if($v == 2)$v = 0;
}
 
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top