PHP- Creating a "success" message for a form

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default PHP- Creating a "success" message for a form

    I am working on a simple form to use as a guesbook. When the user enters thier
    name, subject and commnents the meesage should read 'Your message was
    submitted' ect. But when the page loads it already gives the success message
    before you submit the form. What am I doing wrong? code:<?php
    require_once['Connections/guestbkConn.php'); ?> <?php ini_set ('display_errors'
    , 1); error_reporting (E_ALL &amp; ~E_NOTICE); if ($dbc = @mysql_connect
    (password here)) { if (!@mysql_select_db (database here)) { die (' Could not
    select data base because: ' . mysql_error() . '</p>'); } } else { die ('
    Could not connect to MySQL because : ' . mysql_error() . '</p>'); } $query =
    'INSERT INTO blog (author, subject, comments, date) VALUES
    ('{$_POST['author']}','{$_POST['subject']}','{$_POST['comments']}', NOW())';
    if (@mysql_query ($query)) { print ' Your message has been submitted</p>'; }
    else { print ' Could not submite becuase' . mysql_error() . '. The query was
    $query. </p>'; mysql_close(); } ?> Thank you for visiting my guestbook.
    Please enter your comments below:<br /> <form name='form' method='post'
    action='guestbk.php'> <table width='60%' border='0' cellspacing='0'
    cellpadding='0'> <tr> <td>Name</td> <td><input name='author' type='text'
    id='author' /></td> </tr> <tr> <td>Subject</td> <td><input name='subject'
    type='text' id='subject' /></td> </tr> <tr> <td>Comments</td> <td><textarea
    name='comments' id='comments'></textarea></td> </tr> <tr> <td>&amp;nbsp;</td>
    <td>&amp;nbsp;</td> </tr> <tr> <td>&amp;nbsp;</td> <td><input type='submit'
    name='Submit' value='Submit' /> <input type='reset' name='Submit2'
    value='Reset' /></td> </tr> </table> </form>

    Bloke Guest

  2. Similar Questions and Discussions

    1. #39850 [NEW]: SplFileObject contradictory "failed to open stream: Success"
      From: judas dot iscariote at gmail dot com Operating system: Linux 64bit PHP version: 5CVS-2006-12-16 (CVS) PHP Bug Type: SPL...
    2. creating a "new user" submission form
      Hi I am trying to create a registration form for users to give me their info like name, username/password, billing address and shipping info. This...
    3. "Error Creating Control" and "Cast from String"
      I'm creating a custom date control. In appearance, it's just a textbox and a button. It has three custom properties: CalDate, CalDateType and...
    4. Acrobat Form Submit error: changes VALUE="true" to "0"
      I wrote an HTML page with a form. In the form I had many inputs as in: <INPUT TYPE="radio" NAME="Q1" VALUE="true"> and <INPUT TYPE="radio"...
    5. #25366 [NEW]: form buttons of type "image" dont send "submit" $_POST variable in IE
      From: jordanolsommer at imap dot cc Operating system: Windows XP PHP version: 4.3.2 PHP Bug Type: Variables related Bug...
  3. #2

    Default Re: PHP- Creating a "success" message for a form


    "Bloke" <webforumsuser@macromedia.com> wrote in message
    news:d24ij7$q09$1@forums.macromedia.com...
    >I am working on a simple form to use as a guesbook. When the user enters
    >thier
    > name, subject and commnents the meesage should read 'Your message was
    > submitted' ect. But when the page loads it already gives the success message
    > before you submit the form. What am I doing wrong?
    <snip>

    Wrap the php code in an if statement, check for the form being submitted.

    if(isset($_POST['Submit']))
    {//process your form
    }else {
    // display the form
    }

    You should include some form validation for security.

    HTH

    -Rb

    -Rb Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139