Problem with displaying tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pinzasso
    New Member
    • Aug 2007
    • 4

    #1

    Problem with displaying tables

    This code works fine for most searchs and displays fine. But when a few fields are searched (only one comes to mind) it gives me a msql error on what would be line 11 here.

    [PHP]$result = mysql_query("SE LECT * " . "FROM $_POST[table] " ."WHERE $_POST[col_select] = $_POST[search_text]");
    echo "<table border='1'> <tr>";
    $dataQuery=mysq l_query("SELECT * FROM $_POST[table]"); $TableFieldCoun t = mysql_num_field s($dataQuery);
    for ($Fcount=0; $Fcount<$TableF ieldCount; $Fcount++)
    {
    $field2= mysql_fetch_fie ld($dataQuery, $Fcount);
    $fieldname2= $field2->name;
    echo"<th>".$fie ldname2."</th>";
    }
    echo "</tr>";
    while($row = mysql_fetch_arr ay($result))
    {
    echo "<tr>";
    for ($Fcount=0; $Fcount<$TableF ieldCount; $Fcount++)
    {
    $field3= mysql_fetch_fie ld($dataQuery, $Fcount); $fieldname3= $field3->name;
    echo"<td>".$row[$fieldname3]."</td>";
    }
    echo "</tr>";
    }
    mysql_free_resu lt($dataQuery);[/PHP]
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    You put POST data directly into your queries? No cleaning, no verification, nothing? Not only can that cause SQL syntax errors, but it is a huge security risk.

    What error are you getting?

    Comment

    • pinzasso
      New Member
      • Aug 2007
      • 4

      #3
      I am learning as I go here, but any recomendations on how to make it safer are appreciated (even though this is for a intranet).

      I get:
      Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource

      All other queries work unless I am searching this one field.

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Originally posted by pinzasso
        I am learning as I go here, but any recomendations on how to make it safer are appreciated (even though this is for a intranet).
        isset()
        mysql_real_esca pe_string()

        Originally posted by pinzasso
        Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource

        All other queries work unless I am searching this one field.
        Do you check that $result is a valid result?

        is_resource()

        Do you check to make sure your queries are successful?

        mysql_error()


        Programming isn't just about programming how things will work if they go right, but also handling *everything* that could possibly go wrong.

        Comment

        Working...