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 4 of 4

Thread: $row error

  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Posts
    252
    Thanks
    8
    Thanked 4 Times in 4 Posts

    $row error

    I am trying to retrieve data from my database and use it as a link. I was using the code below on a previous web host.

    PHP Code:
    <?php
             
    // Connect to database server
        
    mysql_connect("host""username","password") or die (mysql_error ());

        
    // Select database
        
    mysql_select_db("database") or die(mysql_error());

        
    // SQL query
        
    $strSQL "SELECT * FROM guard WHERE allegiance = 'Loyal' ORDER BY regname";

        
    // Execute the query (the recordset $rs contains the result)
        
    $rs mysql_query($strSQL);
        
        
    // Loop the recordset $rs
        
    while($row mysql_fetch_array($rs)) {

           
    // Name of the person
          
    $strName $row['regname'];

           
    // Create a link to person.php with the id-value in the URL
           
    $strLink "<a href = 'regiment.html?id = " $row['id'] . "'>" $strName "</a>";

            
    // List link
           
    echo "<li>" $strLink "</li>";

          }

        
    // Close the database connection
        
    mysql_close();
        
    ?>
    However I have just changed to a new host and the code is no longer working. It simply shows the below.

    Loyal Regiments " . $strName . ""; // List link echo "
    " . $strLink . "
    "; } // Close the database connection mysql_close(); ?>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    What does the 'view source' of that output in your browser look like?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Nov 2011
    Posts
    252
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Never mind it was me being dim, my host doesn't recognize mixed PHP/HTML pages.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    There nothing wrong with php/html in a file, as long as the web server knows the file should be parsed as being a .php code file.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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