#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Problem Displaying MySQL Records in a HTML Table


    Hello guys, i am having a problem displaying mysql Records in an html table, as the title says

    The code is this :

    PHP Code:
    <html>
    <head>
    </head>
    <body>
    <?php
                            $con 
    mysql_connect("localhost""root""");
                            if (!
    con) {
                            die (
    "Can not connect: " mysql_error());
                            }
                            
                            
    mysql_select_db ("regform"$con);
                            
                            
    $sql "SELECT * FROM contacts";
                            
    $myData mysql_query($sql$con):
                            echo 
    'test';    
                            echo 
    "<table border = '1'>
                            
                            <tr>
                            <th>Name</th>
                            <th>Lastname</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Comment</th>
                            </tr>"
    ;
                            
                            while(
    $record mysql_fetch_array($myData)) {
                            echo 
    "<tr>";
                            echo 
    "<td>" $record['Name'] . "</td>";
                            echo 
    "<td>" $record['Lastname'] . "</td>";
                            echo 
    "<td>" $record['Phone'] . "</td>";
                            echo 
    "<td>" $record['Email'] . "</td>";
                            echo 
    "<td>" $record['Comment'] . "</td>";
                            echo 
    "</tr>";
                            
                            }
                            
                            echo 
    "</table>";
                            
                            
    mysql_close ($con);
                            
                            
    ?>
    </body>
    </html>

    When i run it it i get this at the browser:

    PHP Code:
    Name Lastname Phone Email Comment "; while($record = mysql_fetch_array($myData)) { echo ""; echo "" . $record['Name'] . ""; echo "" . $record['Lastname'] . ""; echo "" . $record['Phone'] . ""; echo "" . $record['Email'] . ""; echo "" . $record['Comment'] . ""; echo ""; } echo ""; mysql_close ($con); ?> 
    Really i could use some help, i try a lot of hours and i cannot find the what fails !

    Thanks a lot
  2. #2
  3. hiding my <b> from ur <strong>
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2004
    Posts
    959
    Rep Power
    181
    Haven't tested yet, but looks like you have a colon instead of a semi-colon at the end of one line accidentally:

    $myData = mysql_query($sql, $con):

    should be

    $myData = mysql_query($sql, $con);

    ***
    made sure, and this error shouldn't even allow php to run.
    ****
    Enjoy my post? Drop some props by hitting the scales button up top. JBL

    Website Design in Los Angeles and Washington, DC by PoweredPages.com
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    2
    Originally Posted by daprezjer
    Haven't tested yet, but looks like you have a colon instead of a semi-colon at the end of one line accidentally:

    $myData = mysql_query($sql, $con):

    should be

    $myData = mysql_query($sql, $con);

    ***
    made sure, and this error shouldn't even allow php to run.
    He is correct... Use the ';'.
    If you use this ':' it is another way for an if else statement (being the else) on one line.

    Example:
    PHP Code:
    $foo $first $second $third
    is the same as
    PHP Code:
    if ($first) {
        
    $foo $second;
    } else {
        
    $foo $third;

    Source: StackOverflow
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Yea, that doesnt seem to help Really i cant imagine what is going wrong
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Fixed it guys baah, i had it saved as .html.... REnamed it to .php and it worked.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    the MySQL extension you're using is ancient. It's obsolete since 10 years and will be officially deprecated in the next PHP version. This means every call to mysql_connect(), mysql_query() etc. will generate a warning. Switch to one of the "new" extensions.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    2
    Originally Posted by Jacques1
    Hi,

    the MySQL extension you're using is ancient. It's obsolete since 10 years and will be officially deprecated in the next PHP version. This means every call to mysql_connect(), mysql_query() etc. will generate a warning. Switch to one of the "new" extensions.
    You always call people out on this. It is seriously annoying!

    Comments on this post

    • richpri disagrees : Jacques1 is sharing good information. A lot of people are unaware of this and need to find out somehow.
    • ManiacDan agrees
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by tjswebdev
    You always call people out on this. It is seriously annoying!
    Trust me, I find this annoying as well, and I'm a tiny bit more active than you are.

    Maybe you are well aware of all those problems, or maybe you just don't care. But many PHP users do care about the security and quality of their code, they simply don't know how to do it. That's why we keep repeating the same warnings and suggestions.

    If you're a PHP pro, how about writing a MySQLi/PDO tutorial we can link to?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,905
    Rep Power
    6351
    There are a lot of bad things that users do. String interpolation, array usage, SQL injection, database access, memory holes, etc. Jacques has apparently chosen to dedicate his life to the deprecated mysql extension. It's something users need to know just like proper array usage, password hashing, etc. If we have one user being annoying at a specific thing, at least everyone will know that thing. At least he's correct, mysql_* shouldn't be used, PDO is safer.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo