Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP anyone?

Options
  • 31-05-2002 6:14pm
    #1
    Closed Accounts Posts: 517 ✭✭✭


    OK wasent sure to post this here or on webmasters so feel free to move it.
    Ok ive 'modified' this script i got free on www.evilwalrus.com

    I want it to e-mail me whats put in the form but when i run it it sends 2 e-mails one with the feilds filled in and the other blank.

    I think its because when the user loads the page and again when they press send.
    Any help is appreciated.
    <? 
    /******************************************************************************** 
    Guestbook by lyonchik: [email]nerd@kic.kmtn.ru[/email] 
    Contact me to report bugs, give your comments or  
    to develop your own personalized Web applications. 
    
    This is a simple guestbook. It consists only of one file.  
    All you need to do is create a MYSQL database table  and set the variables below  
    to conform to your settings and that's it.  
    The sample query to create a table should be: 
    
     "CREATE TABLE guestbook (id int(5) NOT NULL auto_increment, name varchar(20),  
     email varchar(20), message text, date datetime, PRIMARY KEY (id))" 
      
    And the guestbook is ready to go. Enjoy! 
      
    You can freely distribute this code. For any suggestions and comments write to:  
    'nerd@kic.kmtn.ru'. Feel free to email me URLs where this guestbook works,  
    I would love to hear that my work is appreciated. 
    *********************************************************************************/ 
    
    // Define MYSQL server information 
    $server = 'localhost';                     // MYSQL server; 
    $user = 'x';                              // User to connect to MYSQL server; 
    $password = 'x';                          // Password; 
    $database = 'x';              // The name of the database; 
    $table = 'guestbook';                         // The name of your database table; 
    
    // Define page layout variables 
    $guestbook_name = "Requests";     // Guestbook page name; 
    $titlecolor = 'black';                     // Title font color; 
    $tablewidth = "90%";                     // Table width in pixels or percentage; 
    $bgcolor = '#ffffff';                     // Table background color value (name of hex equivalent); 
    $bordercolor = '#000000';                 // Table border color value (name of hex equivalent); 
    $bordersize = 5;                         // Table border size; 
    $cellspacing = 0;                         // Table cellspacing value; 
    $cellpadding = 5;                         // Table cellpadding value; 
    $messagecellcolor = '#BBAAAA';             // message cell color; 
    $namecolor = '#0000EE';                     // name font color; 
    $messagecolor = '#000099';                 // message font color; 
    $mainfont = '#000033';                     // main text font color; 
    $maxshow = 10;                             // Number of messages to display per page; 
    ?> 
    <HTML> 
    <META http-equiv=Content-Type content="text/html; charset=windows-1251"> 
    <HEAD> 
    <TITLE> 
    <? 
    echo $guestbook_name; 
    ?> 
    </TITLE> 
    <script language="javascript"> 
    function checkForm() 
    { 
    if ((document.forms.myGB.name.value == '') || (document.forms.myGB.message.value == '')) 
    { 
    alert('Fill in required fields!'); 
    } 
    else { 
            document.forms.myGB.submit(); 
            } 
    } 
    </script> 
    </HEAD> 
    <? 
    
    
    echo "<BODY bgcolor=" . $bgcolor . ">"; 
    echo "<div align=center><h1><font color=" . $titlecolor . ">" . $guestbook_name . "</font></h1>"; 
    
    
    
    
    if (isset($message)) 
    { 
    if ($email == "") 
    { 
    $email = "no_email"; 
    } 
    mysql_connect ($server, $user, $password) or die ("Can't connect!"); 
    mysql_select_db ($database) or die ("Can't open database!"); 
    $sql = "INSERT INTO $table (name, email, message, date) VALUES ('$name', '$email', '$message', NOW())"; 
    $result = mysql_db_query($database, $sql); 
    if ($result) 
    echo "<meta http-equiv='Refresh' content='0; URL=" . $PHP_SELF . "'>"; 
    else 
    echo "Error! Check the form!"; 
    mysql_close(); 
    } 
    
    
    
    
    ?> 
    
    <p> 
    (*) Required fields 
    <form name='myGB' action=<? echo $PHP_SELF ?> method='post'> 
    * Name:<br><input type='text' name='name' maxlength=20><br> 
    Email:<br><input type='text' name='email' maxlength=20><br> 
    * Request:<br><textarea name='message' rows=5 cols=30></textarea><br> 
    <a href="javascript:checkForm()">Send</a> 
    </form> 
    </font> 
    </div> 
    <? mail("hacktavist@staticfm106.com", "My Subject", "name :$name\n e-mail: $email\n
    request: $message\n "); ?>
    </BODY> 
    </HTML> 
    


Comments

  • Moderators, Sports Moderators Posts: 8,679 Mod ✭✭✭✭Rew


    Why not have a regualr form eg:

    eg form.html

    <HTML>
    etc.....

    <FORM ACTION="mail.php" METHOD="POST" NAME="MailMe">

    your fields here....

    <INPUT TYPE="submit" NAME="submit" VALUE="Mail it!"><BR><BR><BR>
    </FORM>

    then have mail.php do somthing like....

    <?


    if($HTTP_POST_VARS) {
    mail("hacktavist@staticfm106.com", "My Subject", "name: $HTTP_POST_VARS");
    }

    //etc rest of code blah...

    // maybe a submitted mesg or a redirect header here...?

    ?>


    Or mayby im way off the mark ;)


  • Closed Accounts Posts: 6,601 ✭✭✭Kali


    take that final code line out and place it within the if($message) block... problem solved.


  • Closed Accounts Posts: 517 ✭✭✭hacktavist


    Thanks a million.
    Im a complete newbie when it comes to php.
    Do you think it would be possable for a seperate script to take out the info and e-mail it?


  • Closed Accounts Posts: 6,601 ✭✭✭Kali


    don't quite know what your getting at there.. but anyway

    if you mean take it out of the database, then any script can do that.

    if you mean take the information from the form then only scripts that are specified in the forms ACTION tag can access the information.


Advertisement