Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: php - mysql admin screen +++ Help Please

  1. #1
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php - mysql admin screen +++ Help Please

    hey everyone,

    thanks for all the help this board is. i am very new to php, but i think it is what i am going to need to use to accomplish what i need to. i hope someone out there can help. i have searched all over with no result.

    ok here is what i need. i have a registration page

    http://www.beinhealth.com/test/fmlftlsched.html

    that links to a form i was able to get linked up to my mysql database. that is all working. now what i need to be able to do is make a screen that a novice computer user like a secretary of BE IN HEALTH could go to and download all that have registered for a certain date. i can log into mysql and export it, but i dont want a secretary in there mucking around ya know. is there a way to use the date drop down in the form to export all people registered for that week?

    thanks for any help you can give

    brent


  2. #2
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What i would do is make a page that has a place to enter the date in and then queries the database for user registered on that date. I will write up the code real quick and post it in a few minutes.
    Thanks DD, you saved me countless times

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok, here is the code as promised:
    PHP Code:
    <?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>';
            }
            
            
    // If there are users
            
    else {
            
                
    // Start table to display users
                
    echo '
                    <h3>Users Registerd On '
    .$date.'</h3>
                    
                <table width="400">
                    <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><a href="mailto:'
    .$u['email'].'">'.$u['email'].'</a></td>
                    </tr>'
    ;
                }
                
                
    // End table
                
    echo '
                </table>'
    ;
         }
    }


    // 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>'
    ;
    }

    ?>
    It will require changing the query to have the table name you are using and it will need your sql connection variables. This script just shows the users registered on a specific date. It is untested, but it should work. Hope it helps

    EDIT:
    You can view a slightly modified version of the script here. Just enter 3/22/07 in the date box.
    Last edited by Titan85; 03-22-2007 at 11:32 PM.
    Thanks DD, you saved me countless times

  4. #4
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey thanks for the reply. i have been out of town so i just checked on it. i like your example. i am about to play with the code and see what i can get. in addition to a display, is there a way to export a whole table in csv format? might work well for mail merge and such.

    thanks

  5. #5
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    please forgive my ignorance, but i do not see where i put in mysql and table information. is there supposed to be a call at the top? when i view souce on your example, all i can see is the form part.

  6. #6
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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_hostdatabase_userdatabase_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">&lt;&lt;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
    Last edited by Titan85; 04-02-2007 at 08:37 PM.
    Thanks DD, you saved me countless times

  7. #7
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    awsome.... i got it working. thanks so much for your help and patience with a novice like me. i even got it downloading into a delemeted text file by modifying your code. learning is great with helpful teachers. thanks

  8. #8
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Glad to hear you got it working
    Thanks DD, you saved me countless times

  9. #9
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey titan,

    thanks for all your help. you are a life saver. i am learning alot in the last few days. i am trying to make one of your other codes work with this one. it is on this thread

    http://www.dynamicdrive.com/forums/s...ad.php?t=19115

    my problem is that i can not get the edit link part to work. here is what i got.

    you can see a working example to see errors i am getting for yourself at www.beinhealth.com/form/bih.html and follow the links to search.

    i used edit code from above linked thread with this name search code.

    Code:
    <?php 
        require('link.php'); 
         
    // If search is active 
    if ($_POST['search']) { 
        $date = $_POST['LName']; 
         
        // Get results from database 
        $users = mysql_query("SELECT * FROM `form` WHERE LName = '$date' ORDER BY RegID 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="bih.html">&lt;&lt;Back</a>'; 
            } 
             
            // If there are users 
      // If there are users 
            else { 
             
                // Start table to display users 
                echo ' 
                    <h3>Users Registerd With Last Name of '.$date.'</h3> 
                     
                <table border="1"> 
                    <tr> 
    <td></td><td></td>
                        <td><b>First Name</b></td> 
                        <td><b>Last Name</b></td>
                         <td><b>Date Attending</b></td>
                        <td><b>Email</b></td>
                        <td><b>Phone Number</b></td> 
                    </tr>'; 
                     
                // For each user found 
                while($u = mysql_fetch_array($users)) { 
                 
                    // Show data for each user 
                    echo ' 
                    <tr> 
    	<td><a href="?act=edit&id='/echo $qry['id'];/'>Edit</a></td>
    	<td>'.$u['RegID'].'</td>
                 <td>'.$u['FName'].'</td> 
                  <td>'.$u['LName'].'</td>
                  <td>'.$u['Date'].'</td> 
                  <td>'.$u['EMail'].'</td>
                  <td>'.$u['Phone'].'</td> 
                    </tr>'; 
                } 
                 
                // End table 
                echo ' 
                </table><br><br><a href="bih.html">Back</a>'; 
                
            } 
    } 
    
    
    // If form was not submitted 
    if (!$_POST['search']) { 
        echo ' 
        <form method="post" action=""> 
            <b>Last Name:</b> <input type="text" name="LName" /> 
            <input type="submit" name="search" value="Search" /> 
        </form><br><br><a href="bih.html">Back</a>'; 
    } 
    if ($_GET['act'] == 'edit') {
        require('edit.php');
    } 
    
    ?>

    it is the edit link i can not get to work. i have tried everything that comes to mind with no result. you also mentioned that i could delete records on that other thread using a similar method, can you explain that a bit more? would i use the edit.php coding and change the update line to delete instead? would that work?

    thanks

  10. #10
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ow forgot to say you can search for mcleod and get 3 entries. if i have anything in the edit field though, it either only shows first entry or gives error.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •