I spent last night trying, overnight brooding (in my sleep), and this morning, finally, finding and fixing the errant line in the code below to get it to display in my browser the entries I made in a test name named "users".

So I got is to display every column of every entry. But when I tried a specialized select statement in the query box provided by the form at the very end of this code, when I pressed the "Submit" button, nothing changed; I was still left staring at the table of all the info in "users".

What am I missing in the form?

Thanks much.

Steve Tiano

------------------------------------------------------------------------------------------

<?php

if(!isset($query) || empty($query))
   {$query = "select * from users";}
//stripslashes is necessary because the slect statement is
//coming from a form. In most systems, the magic_quotes
//setting (see Appendix A) will prepend single quotes
//with backslashes, which could be problematic.
$query=stripslashes($query);

mysql_connect("localhost", "name", "password") or die ("Could not connect to database");
mysql_select_db("mysqlphp_db_apps_exerDB") or die ("Could not select database");
$result = mysql_query($query) or die(mysql_error() );


$number_cols = mysql_num_fields($result);

echo "<b>query: $query</b>";
//lay out table header
echo "<table border = 1>\n";
echo "<tr align=center>\n";
for ($i=0; $i<$number_cols; $i++)
{
   echo "<th>" . mysql_field_name($result, $i). "</th>\n";
}
echo "</tr>\n";//end table header

//lay out table body
while ($row = mysql_fetch_row($result))
{
   echo "<tr align=left>\n";
   for ($i=0; $i<$number_cols; $i++)
   {
       echo "<td>";
       if (!isset($row[$i])) //test for null value
           {echo "NULL";}
       else
           {echo $row[$i];}
       echo "</td>\n";
   }
   echo "</tr>\n";
}

echo "</table>";

?>

<form action="<? echo $PHP_SELF?>" method="GET">
   <input type="text" name="query" size="50"><br>
   <input type="submit">
</form>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to