What php script should I use to send contact form to mysql

Discussion in 'PHP' started by innovativecs12, Jan 10, 2011.

  1. #1
    I am really a beginner here I here I know but I have been reading my php book and none of the code they give me to send contact form info to mysql seems to work.
    I am using WAMP on windows xp pro what would be a good php script to send my contact form to my database?

    This is my html contact form:

    <form action="save.php" method="post">
    Name: <input name="name" size="50" type="text"> <br />
    E-mail: <input name="email" size="50" type="text"> <br />
    Subject: <input name="subject" size="50" type="text"> <br />
    Message: <br />
    <textarea rows="20" cols="50" name="message"></textarea><br />
    <input value="Submit!" type="submit">
    </form>
     
    innovativecs12, Jan 10, 2011 IP
  2. darkerx

    darkerx Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #2
    open your save.php file.
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    mysql_query("INSERT INTO table SET `name`='$name', `email`='$email', `subject`='$subject', `message`='$message' ");

    Of couse, first of all you need to connect to mysql database.
     
    darkerx, Jan 10, 2011 IP
  3. Raymond_M

    Raymond_M Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It amazes me how simple everything in php seems to be... if you have any more questions you should check out tizag.com, it's php tutorial helped me alot. PM me with anymore questions if you'd like, i'm new, but wouldn't mind trying to help you figure stuff out as I can learn from it also.
     
    Raymond_M, Jan 10, 2011 IP
  4. qtriangle

    qtriangle Active Member

    Messages:
    179
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #4
    qtriangle, Jan 13, 2011 IP
  5. loog12us

    loog12us Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    connect to db first php-mysql-tutorial.com/wikis/mysql-tutorials/connect-to-mysql-database.aspx
    then use the code given by darkerx to insert into db
     
    loog12us, Jan 13, 2011 IP
  6. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    One tip:
    Don't take input directly and insert into database. In order to protect your site from SQL injection always use mysql_real_escape_string() function to validate input before inserting into database.

    Best Of Luck!! :)
     
    Zetiz, Jan 13, 2011 IP
  7. ankit_frenz

    ankit_frenz Active Member

    Messages:
    1,111
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    63
    #7
    add to that html entities..and stripslashes!!
     
    ankit_frenz, Jan 13, 2011 IP
  8. loog12us

    loog12us Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    if you want to use mysql real escape string function be sure you are connected to db while trying to use this function.
     
    loog12us, Jan 13, 2011 IP
  9. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #9
    Yes, that is a noteworthy point.
     
    Zetiz, Jan 14, 2011 IP
  10. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #10
    Actually it is not necessary to use stripslashes. People use it when magic_quotes_gpc(deprecated) is enabled and the data is not going to be inserted into database that needs escaping. This adds extra slash to the data. To remove the extra slash, in case you want to display the data, stripslashes in used. Refer: http://in3.php.net/manual/en/function.stripslashes.php

    But if you use mysql_real_escape_string() then it is really not necessary to use stripslashes. Rather you could use trim and strip_tags().

    You may refer to this thread in PhpFreaks to understand more- http://www.phpfreaks.com/forums/php-coding-help/(solved)-escape-string-vs-trim-vs-strip-slashes/

    I found it useful.

    Best Wishes. :)
     
    Last edited: Jan 14, 2011
    Zetiz, Jan 14, 2011 IP
  11. loog12us

    loog12us Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    mysql real escape string was added after php version 4.3 , and depreciates the add slashes function that works if gpc magic quotes are on.
     
    loog12us, Jan 15, 2011 IP
  12. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #12
    Ya, thats true.. But mysql_real_escape_strinng() comes to use when there is a database connection but addslashes() doesn't necessarily have to do anything with database connection.
     
    Zetiz, Jan 15, 2011 IP
  13. whippa craka

    whippa craka Greenhorn

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #13
    User your own... thats a very easy script to make. Just look at the guides around here.
     
    whippa craka, Jan 15, 2011 IP
  14. historiasdemaria

    historiasdemaria Member

    Messages:
    138
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #14
    One of the good things about PDO is that you can use the quote($value) function and is that simple!
     
    historiasdemaria, Jan 15, 2011 IP