Need help correcting query
Posted: Sat May 05, 2007 11:07 am
Hello,
I am practicing with the following code. It crashes when I insert the SELECT statement. I am thinking I am not connecting to the database, but am not sure. Can someone please advise?
Many thanks.
Kirk
**********************
I am practicing with the following code. It crashes when I insert the SELECT statement. I am thinking I am not connecting to the database, but am not sure. Can someone please advise?
Many thanks.
Kirk
**********************
Code: Select all
<?php
$usr = $_SERVER['PHP_AUTH_USER'];
$link = mysql_connect('mysql_host', 'mysql_dbusername', 'mysql_dbpassword');
$fields = mysql_list_fields("my_database", "my_table", $link);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
$var1 = mysql_field_name($fields, $i);
// Page crashes when I introduce this line
$var2 = SELECT $var1 FROM my_table WHERE my_fieldname = "'" . $usr . "'";
echo "<input type='hidden' name=" . "'" . $var1 . "'" . " value=" . "'" . $var2 . "'" . "><br />" . "/n";
}
?>