Jump to content


Photo

Something super fishy is going on


  • Please log in to reply
2 replies to this topic

#1 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 20 September 2006 - 05:11 PM

I have a page where I can post pictures, and in order to have them displayed, all you do is paste the URL, one per line and it will auto turn it into a link using the URL pasted, modifying it for the thumbnail and then putting it into a table. 

If I post more than one it seems that it posts extra blank pictures in between them, I have no idea what's going on.  It turns them into a checker pattern.  The <tr> is working correctly after each 7 passes, but for some reason it's putting blank pictures in between the real ones

The full code is:
<?php 
	session_start();

if( !empty($_POST['posttitle']) && !empty($_POST['bodytext']) && !empty($_SESSION['user_level'])) {
include 'db.php';
$posttitle = mysql_real_escape_string(strip_tags($_POST['posttitle']));
$post_body = mysql_real_escape_string(strip_tags($_POST['bodytext']));
$poster = $_SESSION['screenname'];
$posttype = $_POST['posttype'];
$post_time = date("Y-m-d H:i:s");

/* Formatting pics on pics page */ 
if(($posttype == 1) && ($_POST['pic_align'])) {
   if(!empty($_POST['number'])) {
      $number = $_POST['number'];
   } else {
      $number = 7;
   }
   $newlines = array("\n", "\r");
   $body_text = str_replace($newlines, "|", $_POST['bodytext']);
   $body_text = explode("|", $body_text);
   $counter = count($body_text);
   $new_row = 0;
   $post_body = "<table>";
   for($i = 0; $i < $counter; $i++){
      $temp = str_replace(".jpg", "s.jpg", $body_text[$i]); // Auto makes s img url
      $final_string = "<td><a href=$body_text[$i]><img src=$temp></a></td>"; // Completes each link with TD
      if($new_row == 0) $post_body .= "<tr>";
      $post_body .= $final_string;
      $new_row++;
      if($new_row == $number) {
         $post_body .= "</tr>";
         $new_row = 0;
      }
   }
   if($new_row != 0) $post_body .= "</tr>";
   $post_body .= "</table>";
}


//Enter info into the db
mysql_query("INSERT INTO posts (title, post_body, post_time, post_type, poster_name) VALUES('$posttitle','$post_body','$post_time','$posttype','$poster')") or die(mysql_error());
}
header("location: index.php");
exit();
?>

Anyone have a clue what's going on?


#2 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 20 September 2006 - 05:28 PM

Here's an example pic:

[attachment deleted by admin]

#3 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 20 September 2006 - 06:16 PM

After playing around a bit I've found that for some reason there are elements in the array that are blank after each element that contains a real value, so if I set the for loop to do $i += 2 it seems to work correctly, however if anyone can point out why I'm getting blank array elements I'd be grateful




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users