MrXortex Posted June 17, 2012 Share Posted June 17, 2012 Hello I made a file uploading system and whenever a user uploads a file and adds a description. It doesn't comes out the way it is. Example: What I wrote: This is a test that if going to the next line works or not New line 2nd line Added a space above. TEST How it shows up: This is a test that if going to the next line works or not\r\n\r\nNew line\r\n\r\n2nd line\r\n\r\nAdded a space above.\r\n\r\n- TEST Anyone knows what I mess up? Here's the code: <?php include('header.php'); if(isset($_GET['id'])){ $id = mysql_real_escape_string($_GET['id']); $sql = mysql_fetch_array(mysql_query("SELECT * FROM filer WHERE id='$id' LIMIT 1")); $fileInfo = @array_map('mysql_real_escape_string', $sql); if(empty($fileInfo)){ echo ' <script> window.location = "index.php"; </script> '; } } if($inLoggad == true && $userinfo['id'] == $fileInfo['uploader'] && isset($_GET['delete']) && is_numeric($_GET['delete'])){ $delId = $_GET['delete']; mysql_query("DELETE FROM filer WHERE id='$delId'"); mysql_query("DELETE FROM kommentarer WHERE fileID='$delId'"); mysql_query("DELETE FROM rated_files WHERE fil_id='$delId'"); unlink("file/" . $fileInfo['folder_name'] . "/" . $fileInfo['file_name']); rmdir("file/" . $fileInfo['folder_name']); echo '<script>window.location = "index.php"</script>'; } if($inLoggad == true && $userinfo['id'] == $fileInfo['uploader'] && isset($_POST['editDesc'])){ $description = mysql_real_escape_string($_POST['info']); mysql_query("UPDATE filer SET filinfo='$description' WHERE id='" . $fileInfo['id'] . "'"); echo '<script type="text/javascript"> window.location = "view.php?id=' . $_GET['id'] . '" </script>'; } if(isset($_POST['submitComment']) && $inLoggad == true){ $comment = mysql_real_escape_string($_POST['text']); $postedBy = $userinfo['id']; mysql_query("INSERT INTO kommentarer (fileId, text, postedBy, date, exakt_date) VALUES('" . $fileInfo['id'] . "', '$comment', '" . $postedBy . "', '$date', '$exact_date')"); } $hasVoted = mysql_fetch_array( mysql_query("SELECT * FROM rated_files WHERE fil_id='" . $fileInfo['id'] . "' AND anv_id='" . $userinfo['id'] . "'") ); if(isset($_GET['rate']) && is_numeric($_GET['rate']) && isset($_GET['id']) && is_numeric($fileInfo['id']) && $inLoggad == true && empty($hasVoted['fil_id'])){ $rate = $_GET['rate']; $currRatings = mysql_fetch_array( mysql_query("SELECT rank FROM filer WHERE id='" . $fileInfo['id'] . "' LIMIT 1") ); $currRateUp = mysql_fetch_array( mysql_query("SELECT rank_up FROM filer WHERE id='" . $fileInfo['id'] . "' LIMIT 1") ); $currRateDown = mysql_fetch_array( mysql_query("SELECT rank_down FROM filer WHERE id='" . $fileInfo['id'] . "' LIMIT 1") ); if($rate > 0){ $newRatingsUp = $currRateUp['rank_up'] + 1; $newRatings = $currRatings['rank'] + 1; //lنgg till vote mysql_query("UPDATE filer SET rank='$newRatings' WHERE id='" . $fileInfo['id'] . "'"); //lنgg till vote mysql_query("UPDATE filer SET rank_up='$newRatingsUp' WHERE id='" . $fileInfo['id'] . "'"); }else { $newRatingsDown = $currRateDown['rank_down'] + 1; $newRatings = $currRatings['rank'] - 1; //lنgg till vote mysql_query("UPDATE filer SET rank='$newRatings' WHERE id='" . $fileInfo['id'] . "'"); //lنgg till vote mysql_query("UPDATE filer SET rank_down='$newRatingsDown' WHERE id='" . $fileInfo['id'] . "'"); } //lنgg till att anvنndaren har rِstat fِr att undvika att han rِstar igen mysql_query("INSERT INTO rated_files (fil_id, anv_id) VALUES('" . $fileInfo['id'] . "', '" . $userinfo['id'] . "')"); echo '<script type="text/javascript"> window.location = "view.php?id=' . $fileInfo['id'] . '" </script>'; } if(isset($_GET['rate'])){ echo '<script type="text/javascript"> window.location = "view.php?id=' . $fileInfo['id'] . '" </script>'; } ?> <link href="css/view.css" rel="stylesheet" media="screen" /> <link href="css/topbar.css" rel="stylesheet" media="screen" /> <link href="css/loginOverlay.css" rel="stylesheet" media="screen" /> <title>HighPload - <?php echo $fileInfo['real_name']; ?></title> </head> <body> <?php include('includes/topbar.php'); $u = mysql_fetch_array(mysql_query("SELECT * FROM anvandare WHERE id='" . $fileInfo['uploader'] . "' LIMIT 1")); ?> <div id="content"> <div id="view_header"> <a href="index.php"> <img class="logo" src="images/small_logo.png" alt="Go home" /> </a> </div> <!-- top_header --> <span class="border"></span> <div id="info"> <h2 title="Download <?php echo $fileInfo['file_name']; ?>"><img src="images/icons/category-icons/<?php echo $fileInfo['ikon']; ?>.png" alt="<?php echo $fileInfo['ext']; ?>" title="Category: <?php echo $fileInfo['ikon']; ?> (<?php echo $fileInfo['ext']; ?>)" /> <a target="_blank" href="get.php?id=<?php echo $fileInfo['id']; ?>"><?php echo $fileInfo['real_name']; ?></a> (<?php echo $fileInfo['file_name']; ?>)</h2> <span><?php echo $fileInfo['storlek']; ?>MB <font style="color: #B4B4B4;">|</font> <?php echo $fileInfo['nerladdningar']; ?> downloads - Uploaded by <?php echo "<a href='view_account.php?id=" . $fileInfo['uploader'] . "'>" . $u['anvandarnamn'];?></a></span> <span><?php echo $fileInfo['rank_up']; ?> people like this, <?php echo $fileInfo['rank_down']; ?> dislikes this.</span> <span style="color: red";>Click the tittle of the file to Download!</p></span> <?php if($inLoggad == true) { if(!empty($hasVoted['fil_id'])) {echo " ";}else {?> <span class='ratings'><a href='view.php?id=<?php echo $_GET['id']; ?>&rate=1'><img src='images/icons/small_plus.png' alt='' /> Like</a> <a href='view.php?id=<?php echo $_GET['id']; ?>&rate=0'>Dislike</a></span> </span> <?php } }else { echo ""; } if($userinfo['id'] == $fileInfo['uploader']){ ?> <p class="optionLine"><a href="#" class="toggle_editDescription">Edit Description</a> | <a href="#" class="toggle_deleteFile">Delete this file</a><a title="You can't regret this!" style="display: none;" href="view.php?id=<?php echo $fileInfo['id']; ?>&delete=<?php echo $fileInfo['id']; ?>" class="deleteFile">Are you sure?</a></p> <?php } ?> <p class="description"><?php echo str_replace("\n","\n<br />", $fileInfo['filinfo']); ?></p> <div class="edit_description" style="display: none;"> <form action="view.php?id=<?php echo $fileInfo['id']; ?>" method="post"> <textarea name="info"><?php echo $fileInfo['filinfo']; ?></textarea> <input type="submit" name="editDesc" class="editDescBtn" value="" /> </form> </div> </div> <!-- information --> </div> <!-- content --> <div id="commentArea"> <?php $sql = mysql_query("SELECT * FROM kommentarer WHERE fileId='" . $fileInfo['id'] . "' ORDER BY exakt_date ASC");?> <h2>Comments <span>(<?php echo mysql_num_rows($sql); ?>)</span></h2> <ul> <?php while($unique_comment = mysql_fetch_array($sql)){ $unique_comment = array_map('htmlspecialchars', $unique_comment); //get the ID of the user $cid = mysql_fetch_array( mysql_query("SELECT * FROM anvandare WHERE id='" . $unique_comment['postedBy'] . "'") ); $cid = array_map('htmlspecialchars', $cid); //odd or even ?> <li<?php if($i%2){ echo ' class="odd"';} ?>> <p class="title"><a href="view_account.php?id=<?php echo $cid['id']; ?>"><?php echo $cid['anvandarnamn']; ?></a><small> - <?php echo $unique_comment['date'];?></small></p> <p><?php echo str_replace("\n","\n<br />", $unique_comment['text']); ?></p> </li> <?php $i++; } ?> </ul> <?php if($inLoggad){ ?> <div id="newComment"> <form method="POST" action="view.php?id=<?php echo $fileInfo['id']; ?>"> <textarea type="text" name="text" onclick="if(this.value=='Add a Comment...')this.value=''" onblur="if(this.value=='')this.value='Add a Comment...'">Add a Comment...</textarea> <input class="submitBtn" type="submit" name="submitComment" value="" /> </form> </div> <!-- newComment --> <?php }else { ?> <div id="loginToComment"> <p>Please <a href="#" class="loginToggle">login</a> or <a href="register.php" class="logonToggle">register</a> to leave a comment.</p> </div> <?php } ?> </div> <!--commentArea --> <?php include('includes/loginOverlay.php');?> <script src="js/jquery-1.4.2.min.js"></script> <?php include('js/fadein.php'); ?> <script> <?php include('js/loginOverlay.js'); ?> $(document).ready(function() { $('.toggle_editDescription').click(function() { if ($('.description').is(":visible")) { $(".description").slideUp(500,function(){ $('.edit_description').slideDown(1000); }); } else { $(".edit_description").slideUp(1000,function(){ $('.description').slideDown(500); }); } }); $('.toggle_deleteFile').click(function() { $('.toggle_deleteFile').fadeOut(500, function() { $('.deleteFile').fadeIn(500); }); }); }); </script> <span style="display: block; clear: both;"></span> <?php include('footer.php'); ?> </body> </html> And thats it! I hope you guys can find the solution. Thanks. Quote Link to comment Share on other sites More sharing options...
MarPlo Posted June 18, 2012 Share Posted June 18, 2012 Hi Try use nl2br() to description before adding it in mysql: $description = mysql_real_escape_string(nl2br($_POST['info'])); Quote Link to comment Share on other sites More sharing options...
MrXortex Posted June 18, 2012 Author Share Posted June 18, 2012 Didn't work :c Any other help? Quote Link to comment Share on other sites More sharing options...
cpd Posted June 18, 2012 Share Posted June 18, 2012 You should nl2br the code when outputting it. Not inserting it into the database. Wherever your echoing the content just wrap it in nl2br(); and it'll sort it right out Quote Link to comment Share on other sites More sharing options...
MrXortex Posted June 18, 2012 Author Share Posted June 18, 2012 I didn't get you sorry. Can you show me an example? Quote Link to comment Share on other sites More sharing options...
MrXortex Posted June 20, 2012 Author Share Posted June 20, 2012 Come on guys? Anyone? Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 20, 2012 Share Posted June 20, 2012 When you echo the content, it needs to be nl2br($content); Did you look up the nl2br function? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.