+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Comment Box Script

  1. #1
    dbqclassof2012 is offline x10Hosting Member dbqclassof2012 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    15

    Exclamation Comment Box Script

    Hello I am currently working on making a comment box for my website and have had a lot of progress but this end part i have not been able to get. I have the form and everything done it submits it to the database fine but then bringing the comments back to the page it always comes up with this error
    Code:
    Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/dbqclass/public_html/getcomments.php on line 22
    I have not been able to fix this and if anyone could help me it would be greatly appreciated!!!!!Heres the code i am working with
    PHP Code:
    <?php
    // Open Connection To mySQL.
    // Replace 'username' and 'password' with appropiate login values for your server.

    $mysqlLink mysql_connect'localhost' 'username' 'pass' );

    // Select mySQL Database.

    mysql_select_db'comments' $mysqlLink );

    // Create Query To Create Table.

    $sql 'SELECT `name`, `comment_date`, `comment` FROM `comments`';

    // Issue Query.

    $result mysql_query$sql );

    // Loop through results and print them.

    while( $row mysql_fetch_array$result ) ) {
        echo 
    $row'name' ] . $row'comment_date' ] . $row'comment' ];
    }

    // Close mySQL Connection.

    mysql_close$mysqlLink );

    ?>

    IF YOU PROVIED ME WITH MY ANSWER I WILL REWARD YOU WITH OVER 200 CREDITS!
    Last edited by dbqclassof2012; 08-30-2008 at 03:11 PM.
    Thought I did a good job? Please Donate some credits or give some rep.



    :laugh:Thanks:laugh:

  2. #2
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: Comment Box Script

    This might be a quick answer.

    I'm not sure you have to put ' in the $sql

    i.e.

    $sql = 'SELECT name, comment_date, comment FROM comments';

  3. #3
    dbqclassof2012 is offline x10Hosting Member dbqclassof2012 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    15

    Re: Comment Box Script

    Ok thanks for the answer but it didnt work so if you have another answer it would be greatly appreciated
    Last edited by dbqclassof2012; 08-30-2008 at 05:58 PM.
    Thought I did a good job? Please Donate some credits or give some rep.



    :laugh:Thanks:laugh:

  4. #4
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: Comment Box Script

    Quote Originally Posted by dbqclassof2012 View Post
    Ok thanks now trying it out
    Let me know how you get on

  5. #5
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: Comment Box Script

    Edit to the following and tell us what you get:

    PHP Code:
    <?php
    // Open Connection To mySQL.
    // Replace 'username' and 'password' with appropiate login values for your server.

    $mysqlLink mysql_connect'localhost' 'username' 'pass' );

    // Select mySQL Database.

    mysql_select_db'comments' $mysqlLink );

    // Create Query To Create Table.

    $sql 'SELECT `name`, `comment_date`, `comment` FROM `comments`';

    // Issue Query.

    $result mysql_query$sql ) or die(mysql_error());

    // Loop through results and print them.

    while( $row mysql_fetch_array$result ) ) {
        echo 
    $row'name' ] . $row'comment_date' ] . $row'comment' ];
    }

    // Close mySQL Connection.

    mysql_close$mysqlLink );

    ?>
    Also, are you sure that both the table and the database have the name of 'comments'.

    Usually the database name has a name like 'dbqclassof2012_comments' or something. Check phpMyAdmin for the proper database name. It will show the prefix (ie the 'dbqclassof2012_' bit) above all the database names.
    - When in doubt, refer to the PHP manual.

  6. #6
    dbqclassof2012 is offline x10Hosting Member dbqclassof2012 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    15

    Re: Comment Box Script

    I have just tried that but t does not seem to work the error it keeps saying :
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/dbqclass/public_html/getcomments.php on line 21

    so i think it is with the coding but i dont know how to fix it because im not the best coder
    Thought I did a good job? Please Donate some credits or give some rep.



    :laugh:Thanks:laugh:

  7. #7
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: Comment Box Script

    So you tried adding in the 'or die(mysql_error());' bit? The error you are getting is usually returned when you are selecting an invalid database or have an error in your syntax. Try adding the 'or die(mysql_error());' code to the end of all your mysql functions.
    - When in doubt, refer to the PHP manual.

  8. #8
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: Comment Box Script

    I agree with scopey here - all my database names are preceeded by my username.

    i.e. me_databasename.

    The name "comments" sounds too much like a table.

    The line we are refering to is mysql_select_db( 'comments' , $mysqlLink );

    If you are doing multiple pages, it may be worth setting up a connection file rather than putting the connection script into each page. This keeps secure info seperate and easier to manage.

    This is done by setting all the variables in one connection.php file, usually put in a seperate folder in the root and would look something like this

    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_connect= "localhost";
    $database_connect= "databasename";
    $username_connect= "username";
    $password_connect= "password";
    $connect = mysql_pconnect($hostname_connect, $username_connect, $password_connect) or die(mysql_error());
    ?>


    then each file would just have one line at the top to reference this file

    <?php require_once('Connections/exampleconnection.php'); ?>

    And the select db would be

    mysql_select_db($databasename, $connect);
    Last edited by freecrm; 09-01-2008 at 07:02 AM.

  9. #9
    dbqclassof2012 is offline x10Hosting Member dbqclassof2012 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    15

    Re: Comment Box Script

    I'm sorry but i have not been able to get this to work i will give you the whole code everything but the password and could you please change it to what it needs to be because fro some reason i cannot get.

    Code:
    <?php
    // Open Connection To mySQL.
    // Replace 'username' and 'password' with appropiate login values for your server.
    
    $mysqlLink = mysql_connect( 'localhost' , 'dbqclass' , 'Password' );
    
    // Select mySQL Database.
    
    mysql_select_db( 'dbqclass_comments' , $mysqlLink );
    
    // Create Query To Create Table.
    
    $sql = 'SELECT `name`, `comment_date`, `comment` FROM `dbqclass_comments`';
    
    // Issue Query.
    
    $result = mysql_query( $sql );
    
    // Loop through results and print them.
    
    while( $row = mysql_fetch_array( $result ) ) {
        echo $row[ 'name' ] . $row[ 'comment_date' ] . $row[ 'comment' ];
    }
    
    // Close mySQL Connection.
    
    mysql_close( $mysqlLink );
    
    ?>
    So the username is dbqclass if you didn't notice above

    Thanks
    Thought I did a good job? Please Donate some credits or give some rep.



    :laugh:Thanks:laugh:

  10. #10
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Comment Box Script

    for your username, and database name, the prefix, like stated before is:

    yourcpanelname_name

    so, your cPanel name corresponds to the location of your site, like, my website's root would be,

    /home/leafy/public_html/


    since you are on a shared server, it must be preceeded with the name, so that there isn't two people with the database "forums" and writing information over each other.

    have you tried that?



    EDIT: also, try this script in any file, or by itself, like, connectiontest.php

    PHP Code:
    <?php
    # Purpose: Establish a connection to the database
    #
    $dbname 'cpanelname_dbname';
    $dbhost 'localhost';
    $dbusername 'cpanelname_dbuname';
    $dbpassword 'dbpass';
    #
    $dbconnection = @mysql_connect($dbhost$dbusername$dbpassword);
     
    if (
    $dbname != '' && !@mysql_select_db($dbname)) 
     
    {
     
    echo 
    'I could NOT connect to the database! Check the username, password, etc.';
    }
     
     else 
    {
    echo 
    'I connected. The connection is: ' $dbconnection;
    }
    ?>
    Last edited by leafypiggy; 09-01-2008 at 12:01 PM.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. How do you create a Comment Box? Script help please
    By pandaxx in forum Programming Help
    Replies: 10
    Last Post: 08-19-2008, 02:15 AM
  2. Access to 300+ PHP scripts (2500 credits)
    By jonathanyaniv in forum The Marketplace
    Replies: 11
    Last Post: 06-03-2008, 10:58 PM
  3. Replies: 5
    Last Post: 03-07-2008, 08:01 PM
  4. Replies: 8
    Last Post: 12-03-2007, 04:12 PM
  5. Server UP time Script
    By dharmil in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 04-03-2006, 04:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers