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.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What script will do this?

    Ok guys well basically I'm looking for a very basic php script... its like a guestbook but it won't be used for that.

    I want to get a script that basically .... allows me to have people post without really requiring anything else than the post itself.

    All thats gotta happen is the post will be made and the page where all the posts are made will have the posts numbered, first post being #1... and I want to show nothing else besides the post itself with post number.


    I do want to log IP, and time for personal records and incase banning is needed. Thank you.


    For All i care .. all the script wil have is a page where you go make the post...
    another where the posts are saved... and a last page where they are displayed as follows:


    3 Thrid Post
    2 Second post
    1 First post

    After that I will just work everything to look like I want with css, thanks.
    Last edited by Data; 10-04-2004 at 03:42 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    <table width="95%"  align="center" class="content2">
    <?php
    include ("db_connect.php");
    $sql "SELECT * FROM table ORDER BY id DESC LIMIT 10";
    $sql pg_query($sql);
    $x 0;
    while(
    $row pg_fetch_array($sql,NULL,PGSQL_ASSOC))
        {
        
    $class = ($x 2) ? ("class1") : ("class2"); 
        print 
    "<tr><td class=\"$class\"> "$row{"id"] . "</td>  <td class=\"$class\">"$row["comment"] ."</td></tr>\n"
        
    $x++;
        }
    ?>
    </table>
    <form method="post" action="post.php">
    <table width="95%" align="center" class="content2">
    <tr><td class="content2">Name:</td> <td class="content2">&nbsp;<input type="text" name="name"></td></tr>
    <tr><td class="content1">Comment:</td> <td class="content1">&nbsp;<input type="text" name="comment" maxlength="100"></td></tr>
    <tr><td class="content2">Website:</td> <td class="content2">&nbsp;<input type="text" name="website"></td></tr>
    <tr><th class="content1" colspan="2">    <input type="hidden" value="tag" name="page"><input type="submit" value="Tag It!"> <input type="reset" value="Clear It!"></th></tr>    
    </table>
    </form>
    And post.php would be like:

    PHP Code:
    <?php
    if ($HTTP_POST_VARS["comment"] != "")
        {
        
    $comment nl2br(htmlentities($HTTP_POST_VARS["comment"], ENT_QUOTES));
        
    $ip $HTTP_SERVER_VARS['REMOTE_ADDR'];
        
    $sql "INSERT INTO table VALUES (DEFAULT, '$comment', '$ip')";
        
    $sql pg_query($sql);
    ?>
    That is, of course, if you are running PostGreSQL.

    Edit: Opening PHP tag got messed up. ;-;

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heh thanks but what is PostGreSQL.. all i run is mysql

  • #4
    New Coder
    Join Date
    Apr 2004
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I still need help on this =-/.. heh

    I need to know the mysql way of doing it and .. err what databse is named etc.. how paths are defined to database..

    THANKS.
    Last edited by Data; 10-06-2004 at 09:22 AM.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hey Data,

    That script looks to me like it will work with MySQL the query's are universal in this case... you need to open connection your database however, as in that script the file db_connect.php is being used as connection.

    P

  • #6
    New Coder
    Join Date
    Apr 2004
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi.. what exactly do I need to change and how do I open the connection..

    I hve never worked with php and databases.

  • #7
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    http://us4.php.net/mysql

    Read and learn young padawan.

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Essentially, throughout the script, replace pg_ with mysql_

    As for the database connection, replace
    PHP Code:
    include ("db_connect.php"); 
    with:
    PHP Code:
    $db mysql_connect('database_location','username','password') or die("Couldn't connect to the database."); 
    mysql_select_db('database_name'$db) or die("Couldn't select the database"); 
    Just replace the parameters accordingly.

    You've of course got to make sure the database/tables are setup correctly, and even still I'm not sure what other issues you might run into...

    Good luck,
    Sadiq.


  •  

    Posting Permissions

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