Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form input to display databases on hosting

Status
Not open for further replies.

Geronantimo

Technical User
Apr 3, 2006
79
SE
I have found a useful script that can display the databases on a hosting account.

How could I modify it so that the username and password can be entered into a form to return the results (when there is no ability to modify the script)
Code:
<?php

// FILENAME: LIST_MYSQL_DBS.PHP
// ----------------------------

define( 'NL', "\n" );
define( 'TB', '  ' );

// connecting to MySQL.
$conn = @mysql_connect( 'localhost', 'username', 'password' )
        or die( mysql_errno().': '.mysql_error().NL );

// attempt to get a list of MySQL databases
// already set up in my account. This is done
// using the PHP function: mysql_list_dbs()
$result = mysql_list_dbs( $conn );

// Output the list
echo '<ul>'.NL;
 
  ///* USING: mysql_fetch_object()
  //  ---------------------------
  while( $row = mysql_fetch_object( $result ) ):
    echo TB.'<li>'.$row->Database.'</li>'.NL;
  endwhile;
  //*/

  /* USING: mysql_fetch_row()
  // ------------------------
  while( $row = mysql_fetch_row( $result ) ):
    echo TB.'<li>'.$row[0].'</li>'.NL;
  endwhile;
  //*/

  /* USING: mysql_fetch_assoc()
  // --------------------------
  while( $row = mysql_fetch_assoc( $result ) ):
    echo TB.'<li>'.$row['Database'].'</li>'.NL;
  endwhile;
  //*/

echo '</ul>'.NL;

// Free resources / close MySQL Connection
mysql_free_result( $result );
mysql_close( $conn );    

?>
 
If I get you "loud and clear" you want to restrain this file access from the general users
if so you need to protect it by forcing a login

Just a few threads down there is a post named: "jpadie code"
you may review and adapt it.
but as Jpadie mentioned it is not final..
You need for example to be sure that the posted UN and PW will be the expected UN and PW
be sure to protect against SQL injection and more fun...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top