bluebyyou Posted July 2, 2007 Share Posted July 2, 2007 I am having trouble on my photo gallery. Users have the ability to comment on a picture. That works fine, the info is put into the DB no problem. however when the page is reloaded or refreshed the last entry does not show up until another comment is made, at which point the newest comment still doesnt show up. I am not ready to just give out a password for everyone to try it to help me trouble shoot(site not secure at all yet). So I would like to PM someone a username and password. Let me know if you would like to. (preferably someone with quite a few stars under thier name). Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 can u post ur code. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 I will post some of it, the whole page is kind of messy  The form... <form name="addcomment" method="post" action="comment_action.php"> <input type="hidden" name="randnum" value="<?php echo $randnum; ?>"> <input type="hidden" name="picid" value="<?php echo $pictureid; ?>"> <input type="hidden" name="posterid" value="<?php echo $_SESSION['user']; ?>"> <input type="hidden" name="postername" value="<?php echo $_SESSION['fname']." ".$_SESSION['lname']; ?>"> <textarea name="text" cols="49" rows="4"></textarea><br><br> <input name="submitcomment" type="submit" value="submit"><br><br> </form>  comment_action.php <?php include("db_connect.php"); $striptext = stripslashes(strip_tags($_POST['text'])); $finaltext = mysql_real_escape_string($striptext); $now = date("Y-m-d H:i:s"); $query = "INSERT INTO piccomment (picid,posterid,commentdatetime,postername,comment)  VALUES ('$_POST[picid]','$_SESSION[user]','$now','$_POST[postername]','$finaltext')"; query_db($query); $getid = $_POST['picid']; header("location:pic.php?id=$getid"); ?>  and heres the query that grabs from the db  $query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 0,7 ";  If the whole page would be more helpful let me know.     Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Do u have a unique id or primary key something like that for every entry to db. Â Then try this: $query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY id DESC LIMIT 7 "; OR: $query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 "; Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 yeah, there definately is a PK Â and I just tried that, It works the same without the 0 as well. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Did u try the code i mention above. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 Yes I did, sorry I put it in an edit. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Can i check with username and pass if u dont mind. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 PM sent, go to gallery, then click on a picture. You will be able to see and add comments there. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 I did not see any login page while clicking on it. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 Oh im sorry, its on the top right on the index page with a right pointing arrow next to it. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Why u use so dark colors while the bg is also dark. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 It must be showing much darker on your monitor, Im still working on the design, I will keep that in mind before I open it up to people. Were you able to find the login form? Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Yes i login and add comments. Can i ask where ur query for selecting goes. Is this in this page: pic.php Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 Did you notice that your second comment does not show up when the page is reloaded or refreshed?  Yes it is on pic.php   Here is the whole thing (pic.php) if that helps <?php session_start(); // START SESSION (MUST BE FIRST ON EVERY PAGE) include("header.php"); include("db_connect.php"); $strippicid = stripslashes(strip_tags($_GET['id'])); $getid = mysql_real_escape_string($strippicid); $query2 = "SELECT * FROM pic WHERE pictureid = '$getid'"; query_db2($query2); $row2 = mysql_fetch_array($result2); extract($row2); ?> <div id="gallerynav"> <a href="gallery.php"> Go back to the gallery </a> </div> <div id="gallery"> <div id="galfloatleft"> <h2><?php if ($picturetitle == ""){ echo "Untitled"; } else {echo $picturetitle;} ?></h2> </div> <div id="galfloatright"> <br> <a href="#">Prev</a> | <a href="#">Next</a> </div> </div> <div id="gallerynav"> <?php $query = "SELECT * FROM member WHERE memberid = '$pictureuserid'"; query_db($query); $row = mysql_fetch_array($result); extract($row); $timestamp = strtotime($picturedate); $format_date = date("F n",$timestamp); ?> <center> <table> <tr><td align="right">Photographer:</td><td align="left"><?php echo $fname." ".$lname; ?></td></tr> <tr><td align="right">Year:</td><td align="left"><?php echo $pictureyear; ?></td></tr> <tr><td align="right">Day:</td><td align="left"><?php echo $pictureday; ?></td></tr> <tr><td align="right">Date:</td><td align="left"><?php echo $format_date; ?></td></tr> <tr><td align="right">Location:</td><td align="left"><?php echo $picturelocation; ?></td></tr> <?php if ($picturetag != "") { $query = "SELECT * FROM member"; query_db($query); $row = mysql_fetch_array($result); ?> <tr><td colspan="2" align="center"><br /></td></tr> <tr><td colspan="2" align="center">In this photo:</td></tr> <tr><td colspan="2" align="center"> <?php $array = explode(",",$picturetag); foreach ($array as $name) { if (in_array($name,$row)) { $query2 = "SELECT fname,lname FROM member WHERE memberid = $name"; query_db2($query2); $row2 = mysql_fetch_array($result2); echo "<a href='profile.php?id=$name'>$row2[0] $row2[1]</a><br />"; } } }?> </td></tr> </table> </center> </div> <div id="gallery"> <img id="larger" src="<?php echo "uploads/$picturefile"; ?>"> </div> <? if ($_SESSION['auth'] == "yes"){ $randnum = rand(0,99999); ?> <div id="gallery"> <h3>Add a comment:</h3> <form name="addcomment" method="post" action="comment_action.php"> <input type="hidden" name="randnum" value="<?php echo $randnum; ?>"> <input type="hidden" name="picid" value="<?php echo $pictureid; ?>"> <input type="hidden" name="posterid" value="<?php echo $_SESSION['user']; ?>"> <input type="hidden" name="postername" value="<?php echo $_SESSION['fname']." ".$_SESSION['lname']; ?>"> <textarea name="text" cols="49" rows="4"></textarea><br><br> <input name="submitcomment" type="submit" value="submit"><br><br> </form> </div> <?php } ?> <?php $maxcomments = 6; if ($_GET['show'] == 1){$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC ";} if ($_GET['show'] != 1) {$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 ";} query_db($query); $num = mysql_num_rows($result); if ($num > 0){ ?> <div id="gallery"> <div id="galfloatleft"><h2>Comments</h2></div> <div id="galfloatright"> <?php if ($_GET['show'] != "1"){?> <br /><a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $pictureid; ?>&show=1">View All</a> <?php }else{ echo " ";}?> </div> <?php while ($row = mysql_fetch_array($result)) { extract($row); $timestamp = strtotime($commentdatetime); $showdate = date('F j', $timestamp); $showtime = date('g:i a', $timestamp); ?> <div id="comment"> <div id="commentpic"><img src="images/nopic.gif"></div> <div id='commenttext'> <h4><a href="profile.php?id=<?php echo $posterid; ?>"><?php echo $postername; ?></a> wrote: (on <?php echo $showdate; ?> at <?php echo $showtime; ?> )</h4> <p><?php echo $comment; ?></p> </div> </div> <?php } ?> </div> <?php } ?> <?php include("footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Yes i note it. Which mysql version u r using. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 4.1.22 Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Try this: Â if ($_GET['show'] == 1){$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY id DESC "; query_db($query);} if ($_GET['show'] != 1)Â {$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 ";} query_db($query); $num = mysql_num_rows($result); if ($num > 0){ Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 made that change, still having the same problem Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Do u have a id which is just for table to increment every time with code execution in db. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 yeah it is picindex...so i put this: Â f ($_GET['show'] == 1){$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY picindex DESC ";} if ($_GET['show'] != 1)Â {$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 ";} query_db($query); $num = mysql_num_rows($result); if ($num > 0){ Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 If u dont mind add a field in ur table like id and auto increment it in ur table not in coding to put by. And then use it as order by id desc limit 7. Â Hope this will help u. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 picindex is auto increment in the table and not in my code. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Just examining ur code can u tell me from where this $result is coming. $num = mysql_num_rows($result); Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 db_connect.php is included on every page  <?php $mysql_user = "******"; $host = "*******"; $password = "*******"; $db = "******"; $connection = mysql_connect($host,$mysql_user,$password) or die ("Couldn't connect to server.");   $selectdb = mysql_select_db($db,$connection) or die ("Couldn't select Intern database."); function query_db($query) { global $result; $result = mysql_query($query) or die (mysql_error()); return $result; } function query_db2($query2) { global $result2; $result2 = mysql_query($query2) or die (mysql_error()); return $result2; } ?> 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.