runnerjp Posted October 14, 2008 Share Posted October 14, 2008 ok i have a forum and basicly i have added a quick update area for the admin to use... here is my forum.php script <link rel="stylesheet" type="text/css" href="http://www.runningprofiles.com/css/login.css"> <link rel="stylesheet" type="text/css" href="http://www.runningprofiles.com/members/include/style.css"> <?php require_once '../settings.php'; include "connect.php"; //mysql db connection here $id = $_SESSION['user_id']; $puser = get_username($id); $timestamp = time(); $timeout = $timestamp - 180; $username = get_username($_SESSION['user_id']); function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/") . $s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":" . $_SERVER["SERVER_PORT"]); return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } $filename = (selfURL()); //Insert User $insert = mysql_query("REPLACE INTO `useronline` SET `timestamp`='$timestamp', `ip`='" . $_SERVER['REMOTE_ADDR'] . "', `file`='$filename',`user`='$username',`user_id`='" . $_SESSION['user_id'] . "'") or die(mysql_error()); ?> <?php //look to see if the forum is currently locked $sQry = "SELECT `locked` FROM forum_lock LIMIT 1"; $obQry = mysql_query($sQry) or die(sprintf("Could not query forums (%d): %s", mysql_errno(), mysql_error())); $record = mysql_fetch_array($obQry); if (isset($record['locked']) && $record['locked']) { //error message die("Sorry, the forums are currently locked."); } else { //if ok carry on viewing page //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $forum = $_GET['forum']; $data = mysql_query("Select * from forumtutorial_posts where parentid='0' AND forum = '$forum' ORDER BY important, lastrepliedto") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 25; //This tells us the page number of our last page $last = ceil($rows / $page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows; //This is your query again, the same one... the only difference is we add $max into it { ?> <title>forum</title> <p><A href='index.php?page=mainforums'><img src="http://www.runningprofiles.com/images/homeforum.gif" alt="home" border="0" /> </a><A href='index.php?page=post&forum=<?php echo $forum; ?>'><img src="http://www.runningprofiles.com/images/new_post.gif" border="0" /></a></p> <table width="99%" class='forum'> <tr> <td><table class='maintable'> <tr class='headline'><td> </td> <td> </td> <td>Topic</td> <td width=15%>Topic Starter</td> <td width="5%">Replies</td><td width="25%">Last replied time</td></tr> <? //We need to add a Little variable that will automatically increase so that //Each div (container) in the editforum.php script is unique: $CONT_ID = 1; $getthreads = "Select * from forumtutorial_posts where parentid='0' and forum = '$forum' ORDER BY important ASC, lastrepliedto DESC $max"; $getthreads2 = mysql_query($getthreads) or die("Could not get threads"); while ($getthreads3 = mysql_fetch_array($getthreads2)) { $getthreads3[title] = strip_tags($getthreads3[title]); $getthreads3[author] = strip_tags($getthreads3[author]); $getthreads3[important] = strip_tags($getthreads3[important]); $important = $getthreads3['important']; ?> <tr <?php if ($important == 1) { $class = "mainrow1"; } else { $class = "mainrow"; } ?> class="<? echo $class ?>"><td width="6%" height="39" align="center" valign="middle"><? if ($getthreads3[author] == $puser) { ?> <img src="http://www.runningprofiles.com/images/new_posts_icon.gif" alt="My" /> <? } else { ?> <img src="http://www.runningprofiles.com/images/last_post.gif" alt="My" /> <? } ?> <td width="4%" align="center" valign="middle"><?php if ($getthreads3['forumlock'] == 1) { echo ' <img src="http://www.runningprofiles.com/images/quick_lock.gif" alt="locked"/>'; } if ($getthreads3['important'] == 1) { echo '<img src="http://www.runningprofiles.com/images/sticky.gif" alt="sticky"/>'; } ?></td> <td width="45%" valign="top"><div align="left"><a href='index.php?page=message&forum=<? echo $forum; ?>&id=<? echo $getthreads3[postid] ?>'><? echo $getthreads3[title] ?></a> <?php include 'editforum.php'; //Now increase it: $CONT_ID++; ; ?> </div></td> <td align="left" valign="middle"><a href='/members/<? echo $getthreads3[author]; ?>'><? echo $getthreads3[author] ?></a></td> <td align="center" valign="top"><? echo $getthreads3[numreplies] ?></td> <td valign="top"><? $dbtime = $getthreads3['lastrepliedto']; $time = date("F j Y, g:i a", $dbtime); echo $time; ?><br> Last post by <b><? echo $getthreads3[lastposter] ?> </b></td></tr> <? } ?> </table></td> </tr> </table> <br> </a> <p> <? echo "<br>"; } echo "<p>"; // Start links for pages $maxpage = $totalpages == 0 ? 1 : $totalpages; // add this line echo "<p align=center>Page $pagenum of $maxpage <br /> "; // change this // Sets link for previous 25 and return to page 1 if ($pagenum != 1) { $pageprev = ($pagenum - 1); echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&id=$id&pagenum=1\"><<</a> "; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&id=$id&pagenum=$pageprev\">PREV </a> "; } else { echo ""; } // Loop thru all the pages and echo out the links for ($i = 1; $i <= $numofpages; $i++) { if ($i == $pagenum) { echo "[" . $i . "] "; } else { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&id=$id&pagenum=$i\">$i</a> "; } } // Check for straglers after the limit blocks if (($rows % $page_rows) != 0) { if ($i == $pagenum) { echo "[" . $i . "] "; } else { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&id=$id&pagenum=$i\">$i</a> "; } } // Print out the Next 25 and Goto Last page links if (($rows - ($page_rows * $pagenum)) > 0) { $pagenext = $pagenum++; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&id=$id&pagenum=$pagenext\">NEXT </a> "; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&id=$id&pagenum=$totalpages\">>></a> "; } ?> </p> <table width="100%" class='loggedin'> <tr> <td width="4%" height="130" > </td> <td width="61%" align="center" valign="top" ><table width="24%" height="108" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td height="33" colspan="2" align="center"><div align="center"><strong>forum key</strong></div></td> </tr> <tr> <td width="51" height="26" align="center"><div align="center"><img src="http://www.runningprofiles.com/images/quick_lock.gif" alt="locked"/></div></td> <td width="117"><div align="center">Locked Topic</div></td> </tr> <tr> <td height="19" align="center" valign="middle"><div align="center"><img src="http://www.runningprofiles.com/images/sticky.gif" alt="sticky"/></div></td> <td><div align="center">Sticky Topic</div></td> </tr> <tr> <td><div align="center"></div></td> <td><div align="center"></div></td> </tr> </table></td> <td width="35%" >Users viewing forum: <? $result = mysql_query("SELECT * FROM useronline WHERE(file='http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum')"); while($row = mysql_fetch_array( $result )) { $last_active = time() - $row['timestamp']; $onlineuser = $row['user']; } if($last_active < 300) { echo $onlineuser; } ?></td> </tr> </table> <p></p> <?php } ?> and here is my update script <?php $topicid=$_GET['id']; if (isset($_POST['edit'])) { if ($_POST['deletepost'] == 'deletepost'){ $threadid = mysql_real_escape_string( $_POST['id']); mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$topicid'") or die(mysql_error()); mysql_query("UPDATE `forumtutorial_posts` SET `numreplies`=`numreplies`-'1' WHERE `postid`='$id2'") or die(mysql_error()); header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); } else { // $threadid = mysql_real_escape_string( $_POST['id']); $threadid = $CONT_ID; $message = $_POST['message']; echo $message; $query1 = "UPDATE forumtutorial_posts SET post = '$message' WHERE postid='$id2' "; mysql_query($query) or die('Error, query failed'); header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); } }else{ ?> <script src="../../css/SpryCollapsiblePanel.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/css/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" /> <div id="CollapsiblePanel<?PHP // I had to add $CONT_ID that is set in the script that includes this. and ive done it again for the "tabindex" just to ensure it works! echo $CONT_ID; ?>" class="CollapsiblePanel"> <div class="CollapsiblePanelTab" tabindex="<?PHP echo $CONT_ID; ?>"> Edit </div> <div class="CollapsiblePanelContent"> <form name='input' action='index.php?page=message&forum=general&id=<? echo $id ?>' method='post'> <input type="hidden" name="id" value="<?php echo $getreplies3['postid'] ?>"> <div align="center"> <label> <textarea class='inputforum' name="message" id="message" cols="500" rows="5"><? echo $message; ?></textarea> </label> <input type="checkbox" name="deletepost" value="deletepost" /> delete post <br/> <br/> <input type='submit' name='edit' class="submit-btn" value=''/> </div> </form> <? } ?></div> </div> <script type="text/javascript"> <!-- <?PHP //Ive added the variable $CONT_ID here aswell. THIS IS REQUIRED FOR THE //JS to work! ?> var CollapsiblePanel<?PHP echo $CONT_ID; ?> = new Spry.Widget.CollapsiblePanel("CollapsiblePanel<?PHP echo $CONT_ID; ?>", {contentIsOpen:false}); //--> </script> for some reason when i try and update a message all my messages get updated :S... is it because the script is picking up my <? $id2=$getreplies3['postid']; ?> id=<? echo $id2;?> sorry if you cant undertsand ! Quote Link to comment https://forums.phpfreaks.com/topic/128387-cant-update-a-single-field/ Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 try using <?php instead of <? Quote Link to comment https://forums.phpfreaks.com/topic/128387-cant-update-a-single-field/#findComment-665199 Share on other sites More sharing options...
runnerjp Posted October 14, 2008 Author Share Posted October 14, 2008 Nope that didnt do anything... didnt think it wood lol... thanks for trying ... any more suggestions?? Quote Link to comment https://forums.phpfreaks.com/topic/128387-cant-update-a-single-field/#findComment-665499 Share on other sites More sharing options...
runnerjp Posted October 15, 2008 Author Share Posted October 15, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/128387-cant-update-a-single-field/#findComment-666004 Share on other sites More sharing options...
runnerjp Posted October 15, 2008 Author Share Posted October 15, 2008 ok i figured out why but need help in solving how to set it right... basicly im setting it as the main topic id .. `postid`='$topicid' via my url but what i need it to be is something like <? $replies=$getreplies3['postid']; ?> but how can i carry this statement onto my next page... ? as this is on message.php and im calling $replies on editmessage.php?? Quote Link to comment https://forums.phpfreaks.com/topic/128387-cant-update-a-single-field/#findComment-666009 Share on other sites More sharing options...
runnerjp Posted October 15, 2008 Author Share Posted October 15, 2008 ok im getitng somewhere... i can now update the replies... but for some reason it also updates the 1st topic post :S <?php $topicid=$_GET['id']; if (isset($_POST['edit'])) { if ($_POST['deletepost'] == 'deletepost'){ $threadid = mysql_real_escape_string( $_POST['id']); mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$threadid'") or die(mysql_error()); mysql_query("UPDATE `forumtutorial_posts` SET `numreplies`=`numreplies`-'1' WHERE `postid`='$threadid'") or die(mysql_error()); header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); } else { $threadid = mysql_real_escape_string( $_POST['id']); //$threadid = $CONT_ID; $message = $_POST['message']; echo $message; $query = "UPDATE forumtutorial_posts SET post = '$message' WHERE postid='$threadid' "; mysql_query($query) or die('Error, query failed'); header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); } }else{ ?> <script src="../../css/SpryCollapsiblePanel.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/css/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" /> <div id="CollapsiblePanel<?PHP // I had to add $CONT_ID that is set in the script that includes this. and ive done it again for the "tabindex" just to ensure it works! echo $CONT_ID; ?>" class="CollapsiblePanel"> <div class="CollapsiblePanelTab" tabindex="<?PHP echo $CONT_ID; ?>"> Edit</div> <div class="CollapsiblePanelContent"> <form name='input' action='index.php?page=message&forum=general&id=<? echo $id ?>' method='post'> <input type="hidden" name="id" id="id" value="<?php echo $getreplies3['postid'] ?>"> this post id =<?php echo $getreplies3['postid'] ?> <div align="center"> <label> <textarea class='inputforum' name="message" id="message" cols="500" rows="5"><? echo $message; ?></textarea> </label> <input type="checkbox" name="deletepost" value="deletepost" /> delete post <br/> <br/> <input type='submit' name='edit' class="submit-btn" value=''/> </div> </form> ?> Quote Link to comment https://forums.phpfreaks.com/topic/128387-cant-update-a-single-field/#findComment-666019 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.