Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

Thread: Looking for an announcement script

  1. #11
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    I did remove the original table because for whatever reason it was throwing off the site css and rearranging the page. However I was able to still insert the php into another table by itself.

    I searched the [acs | desc] last night but I guess out of everything else I have going on I couldn't get it to work because I was leaving the [ ] in the code. Yeah I know, I'm clueless.

    Anyway, Because the page will be accessed to logged in members only and I can't get the log in's to match I have a work around patch that I would like to use instead. Right now I have it set so that if you are logged into to the site and you visit the page it automatically pastes your username into the "your name" box. However it is still editable so I would like to make the box inactive so it will still input the username but the user won't be able to change it.

    Something else I noticed is that if I make a post on the page and then I refresh the page it posts the same post again. Is that a cookie that's doing that? If so can we delete only that cookie after posts? What I plan on doing is setting the page to refresh about every 10 or so seconds so it will see new posts from other members. Also *just a note* - I do have other cookies on the page that I need to keep, so if we will be deleting cookies we should name is something like commentcook or something off the wall.

    Other than that, the only other thing I would like is the ability to delete the lines, but leave them on the server in case I need to double check something later in life.
    Last edited by Dirt_Diver; 01-07-2009 at 02:40 PM.

  2. #12
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Sorry but I was just thinking, if someone posts a link can we make it clickable?

  3. #13
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    the page reloading on refresh is because, the post still resides on the page.
    i fixed the code to include the checkbox for saving, and also to block the current user in the username field which remains disabled through out his login.

    The save functionality is partially implemented, but whatver else u had asked is present in this code.

    my assumed file name for the following code is "main.php"

    PHP Code:
    <?php session_start(); ?>
    <form id="form1" name="form1" method="post" action="">
      <label>
      <strong>Username</strong>: 
      <input type="text" name="user" id="user" <?php if(isset($_SESSION['user'])){?> disabled="disabled" value="<?php echo $_SESSION['user'];?><?php }?>/>
      </label>
      <p><strong>Comments: </strong></p>
      <p>
        <label>
        <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
        </label>
      </p>
      <p>
        <label>
        <input type="submit" name="button" id="button" value="Submit" />
        </label>
      </p>
    </form>


    <?php session_start(); 

    include(
    'dbconn.php');

    $date date("Y-m-d");
    $time date("g:i a");


    if(isset(
    $_POST['user'])){
    $username $_POST['user'];
    }

    if(
    strlen($username) == 0){
    $sessionUser "hello";
    }

    if(isset(
    $_POST['comments'])){
    $comments $_POST['comments'];
    }

    if(
    strlen($username)>|| strlen($comments)>0){

    //insert this value
    if(strlen($username == 0)){
    $username "Kris";                            //point this value to use the session variable of your current user.
    }
    $insert  "insert into comments(username,time,date,comment)values('$username','$time','$date','$comments');";
    $suc mysql_query($insert);
    $newID mysql_insert_id();

    if(
    $suc){
    $url "redirect.php?mode=redirect";
    header('Location: '.$url);
    }

    }


    //fetch the latest x amount of comments;

    $fetch "select *,id from comments order by date limit 20;";
    $success mysql_query($fetch);
    ?>

    <table width="100%" border="0">

    <?php 
    while($info mysql_fetch_array($success)){ 
    ?>
    <tr>
    <?php if($_SESSION['user'] == "Kris"){?>
    <form id="form2" name="form2" method="post" action="save.php">
    <td align="left">
      <label>
      <input type="checkbox" name="<?php $info['id'];?>" id="save" />
      </label></td><?php }?>
    <td width="21%" align="left" style="color:#006600;"><?php echo ucfirst($info['username']);?><?php echo " &raquo; ".$info['date']."  @".$info['time'];?></td>
    <td width="79%" align="left" style="color:#000000;"><?php echo ucfirst(nl2br($info['comment']));?></td>
    </tr>

    <?php }?>
    </table>

    <?php if($_SESSION['user'] == "Kris"){?>
    <label>
    <input type="submit" name="button2" id="button2" value="Save" />
    </label>
    </form>
    <?php }?>
    second reference code file: redirect.php
    PHP Code:
    <?php session_start();

    $mode $_GET['mode'];

    if(
    $mode == "redirect"){
    header('Location: main.php');
    exit;
    }

    ?>
    Play with it, you might be able to enhance it even further

  4. #14
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    I'm getting a can not modify header error from this.

    PHP Code:
    if($suc){
    $url "redirect.php?mode=redirect";
    header('Location: '.$url);

    Well I was so I deleted it but that's what keeps me from reposting every time I hit refresh right?

    Also what is the save button do? When I check a box and click it, it's sending me to save.php. I don't have a save.php (yet).
    Last edited by Dirt_Diver; 01-07-2009 at 08:44 PM.

  5. #15
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Quote Originally Posted by Dirt_Diver View Post
    I'm getting a can not modify header error from this.

    PHP Code:
    if($suc){
    $url "redirect.php?mode=redirect";
    header('Location: '.$url);

    You cannot use header(); after anything has been sent to the browser. In l_kris06's script, there is a bunch of html above the header(); function. Not to mention the html, head, body tags and so on that should exist on your page.

    Also, this is not going to work:

    PHP Code:
    //insert this value
    if(strlen($username == 0)){
    $username "Kris";                            //point this value to use the session variable of your current user.

    It should be:

    PHP Code:
    if ( strlen($username) == ) { 
    l_kris06 and dirt_diver, you really should get in the habit of using tabs or spaces and line spacing in your code. Especially inside if statements. If you don't it is going to turn into a diaster once the code gets even a little more complex.

    For example, the following is much better:

    PHP Code:
    if ( $suc ) {

        
    $url "redirect.php?mode=redirect";
        
    header('Location: '.$url);

        
    // You could have just wrote: header('Location: redirect.php?mode=redirect'); btw



  6. The Following User Says Thank You to JasonDFR For This Useful Post:

    Dirt_Diver (01-08-2009)

  7. #16
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    Its interesting, i dont get any errors, and it works as expected here.
    besides i have PHP5. not sure.

    You are right here..

    PHP Code:
    //insert this value 
    if(strlen($username == 0)){ //This needs to be if(strlen($username) == 0))
    $username "Kris";                            //point this value to use the session variable of your current user. 

    The save functionality which is not done yet is basically an option where the original poster wanted some of the posts from not being replace with the newer ones. i intend to use that to mark the individual entries in the DB and
    use it later for fetching


    @Dirtdriver,
    you can post clickable links yes but not in the code thats below. Clickable links mean inherent html tags and textarea wont help here, all my applications use "FCKeditor" whever i want user comments. Take a look on the front, its easy to implement here too.

  8. #17
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Okay I have changed the header (); to
    PHP Code:
    if( $suc ) {
    header('Location: redirect.php?mode=redirect');


    And I last night I moved it above the html tags because I was getting the header already sent error.

    Still getting the double posts though. I would assume that the header is supposed to fix that but I don't know if it is. I changed the address from redirect to a page I don't have and I don't see a difference so I'm thinking something isn't working right.

    Kris thanks again so much for your help on this.
    Last edited by Dirt_Diver; 01-08-2009 at 03:05 PM.

  9. #18
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Okay I have added some .js to the mix to allow users to click on a picture and it enter in forum codes like {b} and {i} but how do I get php to see it and produce it on submit?

  10. #19
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Nah, just do something like this:
    Code:
    <?php session_start(); ?> 
    <form id="form1" name="form1" method="post" action=""> 
      <label> 
      <strong>Username</strong>:  
      <input type="text" name="user" id="user" <?php if(isset($_SESSION['user'])){?> disabled="disabled" value="<?php echo $_SESSION['user'];?>" <?php }?>/> 
      </label> 
      <p><strong>Comments: </strong></p> 
      <p> 
        <label> 
        <textarea name="comments" id="comments" cols="45" rows="5"></textarea> 
        </label> 
      </p> 
      <p> 
        <label> 
        <input type="submit" name="button" id="button" value="Submit" /> 
        </label> 
      </p> 
    </form> 
    
    
    <?php session_start();  
    
    include('dbconn.php'); 
    
    $date = date("Y-m-d"); 
    $time = date("g:i a"); 
    
    
    if(isset($_POST['user'])){ 
    $username = $_POST['user']; 
    } 
    
    if(strlen($username) == 0){ 
    $sessionUser = "hello"; 
    } 
    
    if(isset($_POST['comments'])){ 
    $comments = $_POST['comments']; 
    } 
    
    if(strlen($username)>0 || strlen($comments)>0){ 
    
    //insert this value 
    if(strlen($username == 0)){ 
    $username = "Kris";                            //point this value to use the session variable of your current user. 
    } 
    $insert  = "insert into comments(username,time,date,comment)values('$username','$time','$date','$comments');"; 
    $suc = mysql_query($insert); 
    $newID = mysql_insert_id(); 
    
    if(isset($_POST['button2']) || isset($_POST['button'])){
    header('Location: '.$_SERVER['PHP_SELF']);
    }
    
    } 
    
    
    //fetch the latest x amount of comments; 
    
    $fetch = "select *,id from comments order by date limit 20;"; 
    $success = mysql_query($fetch); 
    ?> 
    
    <table width="100%" border="0"> 
    
    <?php  
    while($info = mysql_fetch_array($success)){  
    ?> 
    <tr> 
    <?php if($_SESSION['user'] == "Kris"){?> 
    <form id="form2" name="form2" method="post" action="save.php"> 
    <td align="left"> 
      <label> 
      <input type="checkbox" name="<?php $info['id'];?>" id="save" /> 
      </label></td><?php }?> 
    <td width="21%" align="left" style="color:#006600;"><?php echo ucfirst($info['username']);?><?php echo " &raquo; ".$info['date']."  @".$info['time'];?></td> 
    <td width="79%" align="left" style="color:#000000;"><?php echo ucfirst(nl2br($info['comment']));?></td> 
    </tr> 
    
    <?php }?> 
    </table> 
    
    <?php if($_SESSION['user'] == "Kris"){?> 
    <label> 
    <input type="submit" name="button2" id="button2" value="Save" /> 
    </label> 
    </form> 
    <?php }?>
    Jeremy | jfein.net

  11. The Following User Says Thank You to Nile For This Useful Post:

    Dirt_Diver (01-09-2009)

  12. #20
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    I don't see your changes but let me get the newest code so we are working on the same level. brb.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •