Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple form processing script

    Hello everyone,

    I apologize in advance for my first post being a request, and for my general programming ignorance. I think what I want to do is simple...though it may be more complicated than I suspect. I need a form processing script to take a text box entry and automaticaly print it as html on my webpage. The next time a user submits an entry into the text box, it will print below the first entry. Essentially I want a website that looks like the comments section of a blog. There will be one long list of entries, and one text box at the bottom to add to that list. So...how do I do this? Thanks in advance.

    PS. To get a better idea of what I want: www.jssolomon.com This is what I'm trying to make. Right now, the submissions simply get emailed to me and I have to post them manually.

  • #2
    New Coder
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You'll need a mySQL database to do this the correct way. You could have the data written directly to the HTML page if you wanted, but that would be more prone to troubles.

    This little tutorial should give you the basics of creating a simple mysql database and displaying the data: http://www.php-mysql-tutorial.com/
    I give green rep to those who answer my questions! :)

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    You would be best to set up a MySQL database as mentioned and the present mail form you have would be changed to enter the data into the database. The web page would then query the database.

    This would be a very easy protect once you understand the basics of setting up the MySQL database and how to use PHP to query the database.
    Leonard Whistler

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yea its easy when you get it and fun Good Luck!!!

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you all so much. Glad I get to learn something . I'll be back if I can't get it done.

  • #6
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey buddy- if you want the data send in your email you can create it using the email function in PHP... without creating a database/

    I'll give you a hint how to play the codes.
    if you are using form.. you can use the $_POST function in the submit type of the form and if you are using the <a href></a> you can use the $_GET function with the help of this you can easily display and submit datas.

    I have a questions? what would you like to do in your form?
    1. Do you want the input data being submitted to your email or
    2. you want it to save first in the database before submitting it in your email?

    Ill give you some sample codes:
    if($_POST['btsubmit']=='submit') {
    }
    I think you know this already...

    YOur problem is very easy., I just want to know what do you want to do with it..

    Thnks and Happy COding guyz

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    He doesn't want it emailing. He wants it going into a db automatically. Did you read his original post?

  • #8
    New Coder
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Follow up: I've setup a mysql database/ created a PHP script that seems to be semi-functional...some of the time. It works for the first few entries and then the query stops working.I can't quite figure out what's wrong. Here is my code:

    PHP Code:
    <body>

    <form name="form" method="post">
    <input name="secret" type="text" />
    <input name="send" type="submit" value="Submit" />
    </form>

    <?php
    $dbhost 
    'localhost';
    $dbuser 'XXXXXXX';
    $dbpass 'XXXXXXX';
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
    $dbname 'XXXXXXX';
    mysql_select_db($dbname);
    if(isset(
    $_REQUEST['send']))
    {
       
    $secret $_REQUEST['secret'];
       echo 
    "$secret";
    }
    mysql_query("INSERT INTO secrets (secret) VALUES ('$secret')") or die ('Error, insert query failed');
    $query  "SELECT secret FROM secrets";
    $result mysql_query($query);
    while(
    $row=mysql_fetch_array($result,MYSQL_ASSOC))
    {
        echo 
    "Message :{$row['secret']} <br>";

    mysql_close($conn);
    ?>
    </body>
    I have a feeling it is a problem with how I created the database...because I more or less guessed. Here is what I did.
    1. Created a new database titled 'secret' from my hosting company's custom interface.
    2. Entered the databsae through phpMyAdmin and created a new table labeled 'secrets' with number of fields set to 1.
    3. I set varchar to 200.
    4. Create and index on "1" columns.
    -->I selected my field and set the size to 2.

    And that is all. Is there anything else I should have done? Thanks in advance everyone.
    Last edited by Spookster; 04-12-2007 at 11:23 PM.

  • #9
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well this should be changed like so
    PHP Code:
    if(isset($_REQUEST['send']))
    {
    $secret $_REQUEST['secret'];
    echo 
    "$secret";
    }
    mysql_query("INSERT INTO secrets (secret) VALUES ('$secret')") or die ('Error, insert query failed');

    //to this
    if(isset($_REQUEST['send']))
    {
    $secret $_REQUEST['secret'];
    echo 
    "$secret";
    mysql_query("INSERT INTO secrets (secret) VALUES ('$secret')") or die ('Error, insert query failed');

    Notice I put the query in your if isset... You do this as your only submitting if someone submits something, versus it would insert into db everytime the page was loaded.

  • #10
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by jsolomon View Post
    I set varchar to 200.
    I would consider maybe TEXT instead, good for 65,535 characters. VARCHAR holds only 255 characters and I notice one of your entries is about 170 characters. Someone might end up wanting to enter more than 255 characters.
    Leonard Whistler

  • #11
    New Coder
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I have gotten that issue worked out. One final set of questions and I should be complete. Here is my code now:

    PHP Code:
    <?php
    $dbhost 
    'localhost';
    $dbuser 'XXXXXXX';
    $dbpass 'XXXXXXX';
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
    $dbname 'XXXXXXX';
    mysql_select_db($dbname);
    $ip $REMOTE_ADDR;
    if(isset(
    $_POST['send']))
    {
       
    $secret $_POST['secret'];
       
    mysql_query("INSERT INTO secret (secret) VALUES ('$secret')") or die ('Error, insert query failed');
       
    mysql_query("INSERT INTO secret (ip) VALUES ('$ip')") or die ('IP log failed');
    }

    $query  "SELECT secret FROM secret";
    $result mysql_query($query);
    while(
    $row=mysql_fetch_array($resultMYSQL_ASSOC))
    {
        print 
    "<p>{$row['secret']}<hr /></p>";
    }
    mysql_close($conn);
    ?>
    I have two problems.
    1. For some reason, the <hr> tag that I want to seperate each entry appears twice... You can see here: www.jssolomon.com/test.php I cannot for the life of me figure out why that's happening.
    2. I want the list to appear in reverse chronological order (the most recent entries on the top). Do I do that by rearranging the database or through PHP?

    Gracias!
    Last edited by Spookster; 04-12-2007 at 11:24 PM.

  • #12
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well your inserting blank information

    PHP Code:
    mysql_query("INSERT INTO secret (secret) VALUES ('$secret')") or die ('Error, insert query failed');
    mysql_query("INSERT INTO secret (ip) VALUES ('$ip')") or die ('IP log failed'); 
    You have two inserts there making two different rows. One row containts the secret text or w/e. The next row contains ONLY the ip so the field "secret" shows blank so thats where your 2nd hr is coming from. Combine the two inserts like this.
    PHP Code:
    mysql_query("INSERT INTO secret (secret,ip) VALUES ('$secret','$ip')") or die ('Error, insert query failed'); 

  • #13
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by jsolomon View Post
    2. I want the list to appear in reverse chronological order (the most recent entries on the top). Do I do that by rearranging the database or through PHP?

    Gracias!

    You would use MySQL and PHP. Create a TIMESTAMP column and ORDER BY time, either DESC or ASC. TIMESTAMP will automatically be filled whenever a new record is added.
    Leonard Whistler

  • #14
    New Coder
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Final Tweak

    Edit: I fixed this issue, so don't bother responding to this post. The problem, for anyone who cares, was that magic_quotes_runtime was set to on, so when I ran addslashes() to my database insert it added a second backslash. All fixy now, thanks.

    Well, with your help I have made this: www.jssolomon.com

    It pretty much does everything I wanted. There is one last issue that I can't seem to figure out. Whenever someone submits an entry, single quotation marks become /' and double quotes become /". I want to get rid of that forward slash... Here is the relevant code:
    PHP Code:
    $insert "INSERT INTO secret (secret,ip,time) VALUES ('$secret','$ip','$time')";
    $select  "SELECT secret FROM secret ORDER BY timestamp DESC";
    mysql_query($insert);
    $result mysql_query($select);
    while(
    $row=mysql_fetch_array($resultMYSQL_ASSOC))
        {
        print 
    "<p>";
        print 
    htmlspecialchars($row['secret'], ENT_QUOTES);
        print 
    "<hr></p>";
        }
    }
    }
    mysql_close($conn);
          
    ?> 
    I know it has to do with the htmlspecialcharas line, though I don't know what to change. I tried changing
    PHP Code:
    print htmlspecialchars($row['secret']) 
    to this
    PHP Code:
    print htmlspecialchars($row['secret'], ENT_QUOTES); 

    But that didn't work. Any suggestions? By the way, feel free to contribute if you feel inspired . Thanks in advance.
    Last edited by jsolomon; 04-09-2007 at 01:59 AM.

  • #15
    Registered User
    Join Date
    Apr 2006
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just thought I'd tell you to never post your MySQL info on the web as you did in one of your posts.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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