Do you mean how do you connect to the sql database? If so, what I did was include a file that had the connection data in it. Here is how you connect to a mysql database:
PHP Code:
$connect = mysql_connect(database_host, database_user, database_pass);
mysql_select_db(database_name, $connect) or die ("Error selecting database! <br />" .mysql_error());
I did some updating to the code, here is the new code:
PHP Code:
<?php
require('config.php');
// If search is active
if ($_POST['search']) {
$date = $_POST['date'];
// Get results from database
$users = mysql_query("SELECT * FROM `users` WHERE date = '$date' ORDER BY id DESC") or die ('Error Getting Users! \n<br />\n' .mysql_error());
$chk = mysql_num_rows($users);
// If no users found
if ($chk < 1) {
echo 'There are no users registered on the date: <b>'.$date.'</b>
<br />
<a href="index.php"><<Back</a>';
}
// If there are users
else {
// Start table to display users
echo '
<h3>Users Registerd On '.$date.'</h3>
<table width="500">
<tr>
<td><b>ID</b></td>
<td><b>Username</b></td>
<td><b>Email</b></td>
</tr>';
// For each user found
while($u = mysql_fetch_array($users)) {
// Show data for each user
echo '
<tr>
<td>'.$u['id'].'</td>
<td>'.$u['username'].'</td>
<td>'.$u['email'].'</td>
</tr>';
}
// End table
echo '
</table>';
echo "<a href=\"?act=download&d=$date\">Text File</a>";
}
}
// If form was not submitted
if (!$_POST['search']) {
echo '
<form method="post" action="">
<b>Date:</b> <input type="text" name="date" />
<input type="submit" name="search" value="Search" />
</form>';
}
if ($_GET['act'] == "download") {
require('make_file.php');
}
?>
And make_file.php (makes the text that appears in the frame that can be copied):
PHP Code:
<?php
$date = $_GET['d'];
$users = mysql_query("SELECT * FROM `users` WHERE date = '$date'") or die ('Error Getting Users! \n<br />\n' .mysql_error());
$add .= 'Users Registered On '.$date.'
';
while($u = mysql_fetch_array($users)) {
$add .= '
User ID: '.$u['id'].'
Username: '.$u['username'].'
Email: '.$u['email'].'
';
}
$file = "registry.txt";
$fp = fopen($file, "w");
fwrite($fp, $add);
fclose($fp);
echo'<meta http-equiv="refresh" content="0;registry.txt" />';
?>
In order for the copy friendly text to be made, you must put a file named registry.txt in the same directory as the rest of the script and chmod it to 777 (can be done using an FTP client, just right click and it should have something like "properties").
Hope this helps
Bookmarks