Page 1 of 4 123 ... LastLast
Results 1 to 10 of 34

Thread: Guestbook posting problem

  1. #1
    Join Date
    Jul 2008
    Location
    boston, ma
    Posts
    88
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Guestbook posting problem

    Hello,
    I built a guest book using a tutorial. When I post a message, an error message pops up then goes away. And the message doesn't post.
    Here is a screenshot of the message.
    Here is the link to the guestbook.
    Can anyone help?
    Thanks

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

    Default

    We would need to see your code but it looks like...

    ...ardgb18.dat has to be giving the cdmod 777 permissions/
    ...the flock function on line 424 had the wrong parameters passed.
    ...the fclose isn't referring back to the fopen, or the fopen is wrong.
    Please post a link to the page on your site that contains the problematic script so we can check it out.

    Please include your code so that we can take a look at it, we can't do much without it.
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2008
    Location
    boston, ma
    Posts
    88
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    I gave a link to the page in my first post.
    here is the code where I believe the errors are.

    PHP Code:

       if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && eregi("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$",$_SERVER['HTTP_X_FORWARDED_FOR'])) {
           $ipnum = $_SERVER['HTTP_X_FORWARDED_FOR'];
       } else {
           $ipnum = getenv("REMOTE_ADDR");
       }

       $newdata = "|~|$idx|~|$tgl|~|$vname|~|$vemail|~|$vcomment|~|$vurl|~|$ipnum|~|";
       $newdata = stripslashes($newdata);
       $newdata .= $newline;

       if (!is_spam($newdata)) {
            $tambah = fopen($data_file,"ardgb18.dat");
            if (strtoupper($os)=="UNIX") {
                if (flock($tambah,LOCK_EX)) {
                    fwrite($tambah,$newdata);
                    flock($tambah,LOCK_UN);
                }
            } else {
                fwrite($tambah,$newdata);
            }
            fclose($tambah);

            //--send mail
            if (strtoupper($notify) == "YES") {
                $msgtitle = "Someone signed your guestbook";
                $vcomment = str_replace(""","\"",$vcomment);   
                $vcomment = stripslashes($vcomment);
                $vcomment = str_replace("<br>","\n",$vcomment);
                $msgcontent = "Local time : $tgl\n\nThe addition from $vname :\n----------------------------\n\n$vcomment\n\n-----End Message-----";
                @mail($admin_email,$msgtitle,$msgcontent,"From: $vemail\n");
            }
            //--clear session
            $_SESSION['name'] = "";
            $_SESSION['email'] = "";
            $_SESSION['url'] = "http://";
            $_SESSION['comment'] = "";
            $_SESSION['add']++;
            $_SESSION['secc'] = "";
            redir($self,"Thank you, your entry has been added.");
        } else {
            redir($self,"Sorry, your entry can't be added into the guestbook.");
        }
    break;

    case "del":
       $record = file($data_file);
       $jmlrec = count($record);
       for ($i=0; $i<$jmlrec; $i++) {
           $row = explode("|~|",$record[$i]);
           if ($id == $row[1]) {
              ?>
              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
              <html>
              <head>
              <title>Delete record</title>
              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
              </head>
              <body bgcolor="<?=$background?>" style="font-family:<?=$font_face?>">
              <div align="left">
              <font size="4" color="<?=$title_color?>">Delete Confirmation</font>
              <br><br>
              <table border="0" cellpadding="5" cellspacing="1" width="450">
                <tr>
                <td bgcolor="<?=$table_top?>">
                <font size="2">
                <font size="1"><b><?=$row[2]?></font><br><?=$row[3]?></b> - <a href="mailto:<?=$row[4]?>"><?=$row[4]?></a>
                <br><br><?=$row[5]?>
                <br><br><font size="1">IP : <?=$row[7]?></font>
                </font> 
                </td>
                </tr>
              </table>
              <form action="<?=$self?>" method="post">
                  <input type="hidden" name="do" value="del2">
                  <input type="hidden" name="id" value="<?=$id?>">
                  <input type="hidden" name="page" value="<?=$page?>">
                  <font color="<?=$title_color?>" size="2"><b>Admin password : </b></font> <input type="password" name="pwd">
                  <br><br>
                  <font size="2" color="<?=$title_color?>"><b>&raquo;</b><input type="checkbox" name="byip" value="<?=$row[7]?>"> Delete all records that using this IP : <?=$row[7]?></font>
                  <br><br>
                  <input type="submit" value="Delete"> <input type="button" value="Cancel" onClick="window.location='<?="$self?page=$page"?>'">
              </form>
              </div>
              </body>
              </html>
              <?
           
    }
       }      
    break;

    case 
    "del2":
       
    $pwd = isset($_POST['pwd']) ? trim($_POST['pwd']) : "";
       
    $id = isset($_POST['id']) ? trim($_POST['id']) : "";
       
    $page = isset($_POST['page']) ? $_POST['page'] : 1;
       
    $byip = isset($_POST['byip']) ? $_POST['byip'] : "";

       if (
    $pwd != $admin_password) {
             
    redir("$self?page=$page","Invalid admin password !");
       }

       
    $record file($data_file);
       
    $jmlrec count($record);
       for (
    $i=0$i<$jmlrec$i++) {
           
    $row explode("|~|",$record[$i]);
           if (
    $byip == "") {
               if (
    $row[1] == $id) {
                   
    $record[$i] = "";
                   break;
               }
           } else {
               if (
    $row[7] == $byip) {
                   
    $record[$i] = "";
               }
           }
       }

       
    $update_data fopen($data_file,"w");
       if (
    strtoupper($os) == "UNIX") {
          if (
    flock($update_data,LOCK_EX)) {
             for (
    $j=0$j<$jmlrec$j++) {
                 if (
    $record[$j] != "") {
                     
    fputs($update_data,$record[$j]);
                 }
             }
             
    flock($update_data,LOCK_UN);
          }
       } else {
             for (
    $j=0$j<$jmlrec$j++) {
                 if (
    $record[$j] != "") {
                     
    fputs($update_data,$record[$j]);
                 }
             }
       }
       
    fclose($update_data);
       
    redir("$self?page=$page","Record has been deleted !");
    break;
    //--end switch


    function redir($target,$msg) {
    global 
    $background,$font_face,$title_color;
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="refresh" content="1; url=<?=$target?>">
    </head>
    <body bgcolor="<?=$background?>">
    <div align="center"><font color="<?=$title_color?>" face="<?=$font_face?>"><h3><?=$msg?></h3>Please wait...</font></div>
    </body>
    </html>
    <?
    exit;
    }

    function 
    input_err($err_msg,$linkback=true) {
    global 
    $background,$font_face;
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Error !</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="<?=$background?>">
    <div align="center">
    <br>
    <table border="1" bgcolor="#000000" cellspacing="0" cellpadding="6">
    <tr>
        <td bgcolor="#FFCC00" align="center">
            <font size="3" color="#000000" face="<?=$font_face?>"><b><?=$err_msg?></b><br>
            <?if ($linkback) {?>
            <font size="2">Click <a href="javascript:history.back()">here</a> and try again.</font>
            <?}?>
            </font>
        </td>
    </tr>
    </table>
    </div>
    </body>
    </html>
    <?
    exit;
    }

    function 
    is_spam($string) {
        
    $data "spamwords.dat";
        
    $is_spam false;
        if (
    file_exists($data)) {
            
    $spamword file($data);
            
    $jmlrec count($spamword);
            for (
    $i=0$i<$jmlrec$i++) {
                
    $spamword[$i] = trim($spamword[$i]);
                if (
    eregi($spamword[$i],$string)) {
                    
    $is_spam true;
                    break;
                }
            }
        }
        return 
    $is_spam;
    }
    ?></p>

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

    Default

    Is the above page guest_book.php?
    Jeremy | jfein.net

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    This is a text version of the error:

    Warning: fopen(ardgb18.dat) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\guestbook\guest_book.php on line 422

    Warning: flock() expects parameter 1 to be resource, boolean given in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\guestbook\guest_book.php on line 424

    Warning: fclose(): supplied argument is not a valid stream resource in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\guestbook\guest_book.php on line 431


    I could give you a new set of script that writes to a textfile then displays the results back on the main page. You can see it functioning here http://www.travelinchucks.com/qa.php. (this also has a user side panel where they can comment back to comments) This uses 1 text file and 2-4 php pages depends on what functions you want.

  6. #6
    Join Date
    Jul 2008
    Location
    boston, ma
    Posts
    88
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    That's sweet Chris!
    Is it fully customizable? and easy to implement? Unlike you, I am not a genius with php, I actually know nothing!!!! ha

    Thanks
    Will

  7. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Yea its real easy....I think and customizable
    Last edited by bluewalrus; 01-08-2009 at 02:37 AM.

  8. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Thumbs up

    You need a txt file with permissions on it set to 777. Then change this "nameofthetextfilegoeshere" to that name.

    This will display all the entries in the guestbook. The outside div is optional and customizable I think you get that part...
    PHP Code:
    <div style="width:650px; height:425px; overflow:auto; border:1px solid #000000;">
    <?php 
    $myFile 
    "questions.txt";
    $fh fopen($myFile'r');
    $theData fread($fh20000000);
    fclose($fh);
    $notesout str_replace("\r""<br/>"$theData); echo $notesout;
    ?>
    </div>
    This is the part where the user will enter there information for the book... Replace nameofform with the name of the php file you make with the next block of code below this (if you want to log ip address or anything like that, that would be done here also.)
    Code:
    <form method="post" action="nameofform.php" style="border:#000000 2px solid; width:375px;">
    <ul style="padding:0; margin:0; list-style-type:none; display:inline;">
    <li style="display:inline;">Your Name:</li><input type="text" name="name" size="35" />
    <br />
    <li style="display:inline;">Your Email:</li></ul><input type="text" name="email" size="35" /><div style="padding-bottom:5px;"></div><br />
    <textarea name="question" rows="4" cols="44">Questions about traveling, financial assistance, or why we do what we do ask them here...</textarea>
    <br /><center>
    <input type="submit" value="Send Your Question" style="text-align:center;" />
    </center></form>
    This checks the entry the user submits then writes it to the text file which is then displayed... Name this what you used above in the action field.
    PHP Code:
    <?php
    $visitor 
    $_POST['name'];
    $visitormail $_POST['email'];
    $notes $_POST['question'];

    if(!
    $visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
    {
    echo 
    "<h2>The e-mail address you entered was not correct.</h2>\n";
    die (
    "<br />Your question has not been submitted. This page will bring you back<br />in 20 seconds or you may use your browsers back menu to resubmit.\n</div>
    </div>
    </body>
    </html>"
    );
    }
    if(
    $notes == "Questions about traveling, financial assistance, or why we do what we do ask them here..."
    {
    echo 
    "Please enter your Question. In the question field";
    die (
    "<br />You may use your browsers back button or this page will bring you back in 20 seconds.</div>
    </div>
    </body>
    </html>"
    );
    }


    if(empty(
    $visitor) || empty($visitormail) || empty($notes )) {
    echo 
    "<br />Please Fill in all of the information.\n";
    die (
    "<br />You may use your browsers back button or this page will bring you back in 20 seconds.</div>
    </div>
    </body>
    </html>"
    );
    }
    $sendata="Email Address to respond to:"$visitormail;
    $q="Comment from "$visitor " "$notes "Submitted:" $todayis ;
    $todayis date("l, F j, Y, g:i a") ;
    $attn $attn ;
    $subject "WHATEVERYOUWANTSUBJECTOFEMAILTOBE";
    $notes stripcslashes($notes);
    $message $todayis [EST] \n
    From: 
    $visitor ($visitormail)\n
    Additional Info : IP = 
    $ip \n
    Browser Info: 
    $httpagent \n
    Referral : 
    $httpref \n
    "
    ;

    $from "From: $visitormail\r\n";


    //OPTIONAL IF YOU WANT AN EMAIL EACH TIME A ENTRY IS POSTED mail("EMAILADDRESS@DOMAIN.COM", $subject, $sendata, $q);
    $File "nameofthetextfilegoeshere.txt";
    $Handle fopen($File"r+");
    $Data '<p class="q">From:' $visitor .  '<br />Submitted on:' $todayis '<br />' $notes '</p><hr />' "\n";
    if (
    $Data <> "")
    {    
        
    $existingText file_get_contents($File);
        
    fwrite($Handle$Data $existingText "\n");
    }
    fclose($Handle);
    ?>
    This doesn't have the admin side where you could edit posts and such if you want that its a little more but still uses that one text file and another form and another php section. If you want it with working terms as oppesed to the name such and such let me know .... If you want to add more or less things you can add them into the form and then in the second php part post['inputfieldsname'] defines the input to the variable on the other side of that equation then use that in the php. Make sense?
    Last edited by bluewalrus; 01-08-2009 at 02:43 AM. Reason: added more explanation

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

    Default

    Nice bluewalrus. Here's a tip: When using double quotes there is no need for concatenation.
    But otherwise looks pretty good.
    Jeremy | jfein.net

  10. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You mean like this there's no need for?
    PHP Code:
    '</p><hr />' "\n" 
    When I tried it before with the \n inside it was displaying on the page as text.I found some other forum that said double quote it and keep it outside and that seemed to work. Once I get things working I tend to stop playing around with them until there's a needed change, hah (if there's a much more efficient way I'll give it a try).
    Last edited by bluewalrus; 01-08-2009 at 05:10 AM. Reason: used a word wrong

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
  •