Skip to main content
added 123 characters in body; edited tags; edited title
Source Link
palacsint
  • 29.9k
  • 9
  • 81
  • 156

Please review the following code and list all the coding errors and poor coding practices that you can see in this code Database output function

Please review the following code and list all the coding errors and poor coding practices that you can see in this code.

function output()
{
    // Check authorization
    if(is_authorized())
    {
        $authorized = true;
        include('/path/to/' . $_REQUEST['module'] . '.php');
    }
    echo "<ul>"
    $conn = mysql_connect( "dbserver.com:6789", "dbyuser", "dbpassWd" );
    mysql_select_db( "kum", $conn ); // selects a database
    $q = " SELECT * FROM main WHERE id > " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        echo "<li>".$row['description']."</li>";
    }
    echo "</ul><br><ul>";
    $q = " SELECT * FROM main WHERE id < " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        // Display the status if it is authorized, othewiseotherwise display N/A
        echo "<li>".$row['description']. "(" .
        $authorized ? $row['status'] : "N/A" . ")</li>";
    }
    echo "</ul>";
}

Please review the following code and list all the coding errors and poor coding practices that you can see in this code

function output()
{
    // Check authorization
    if(is_authorized())
    {
        $authorized = true;
        include('/path/to/' . $_REQUEST['module'] . '.php');
    }
    echo "<ul>"
    $conn = mysql_connect( "dbserver.com:6789", "dbyuser", "dbpassWd" );
    mysql_select_db( "kum", $conn ); // selects a database
    $q = " SELECT * FROM main WHERE id > " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        echo "<li>".$row['description']."</li>";
    }
    echo "</ul><br><ul>";
    $q = " SELECT * FROM main WHERE id < " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        // Display the status if it is authorized, othewise display N/A
        echo "<li>".$row['description']. "(" .
        $authorized ? $row['status'] : "N/A" . ")</li>";
    }
    echo "</ul>";
}

Database output function

Please review the following code and list all the coding errors and poor coding practices that you can see in this code.

function output()
{
    // Check authorization
    if(is_authorized())
    {
        $authorized = true;
        include('/path/to/' . $_REQUEST['module'] . '.php');
    }
    echo "<ul>"
    $conn = mysql_connect( "dbserver.com:6789", "dbyuser", "dbpassWd" );
    mysql_select_db( "kum", $conn ); // selects a database
    $q = " SELECT * FROM main WHERE id > " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        echo "<li>".$row['description']."</li>";
    }
    echo "</ul><br><ul>";
    $q = " SELECT * FROM main WHERE id < " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        // Display the status if it is authorized, otherwise display N/A
        echo "<li>".$row['description']. "(" .
        $authorized ? $row['status'] : "N/A" . ")</li>";
    }
    echo "</ul>";
}
Tweeted twitter.com/#!/StackCodeReview/status/214622269450878977
Source Link

Please review the following code and list all the coding errors and poor coding practices that you can see in this code

function output()
{
    // Check authorization
    if(is_authorized())
    {
        $authorized = true;
        include('/path/to/' . $_REQUEST['module'] . '.php');
    }
    echo "<ul>"
    $conn = mysql_connect( "dbserver.com:6789", "dbyuser", "dbpassWd" );
    mysql_select_db( "kum", $conn ); // selects a database
    $q = " SELECT * FROM main WHERE id > " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        echo "<li>".$row['description']."</li>";
    }
    echo "</ul><br><ul>";
    $q = " SELECT * FROM main WHERE id < " . $_GET["id"]. ";";
    $res = mysql_query( $q, $conn);
    while( $row = mysql_fetch_assoc( $res ) )
    {
        // Display the status if it is authorized, othewise display N/A
        echo "<li>".$row['description']. "(" .
        $authorized ? $row['status'] : "N/A" . ")</li>";
    }
    echo "</ul>";
}