Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

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

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

    Default

    i got it!!! well the link part

    i used <a href="edit.php?RegID='.$u['RegID'].'">Edit</a> as the link and it seems to work.

    still when i run the edit it does not update. here is the code. can you tell me what i have wrong?

    Code:
    <?php
        require('link.php'); 
    
    // Get the user id
    $id = $_GET['RegID'];
    
    // Get data from user with the specified id
    $info = mysql_query("SELECT * FROM `form` WHERE RegID = '$id'") or die ('Error Getting User Data! <br />' .mysql_error());
    $chk = mysql_num_rows($info);
    $u = mysql_fetch_array($info);
    
    // If edit not hit
    if (!$_POST['edit']) {
    
        // If user id returns no results
        if ($chk < 1) {
            echo 'The user with the id <b>'.$id.'</b> does not exist!';
        }
        else {
            // Edit Form
            ?>
        <!-- Edit Form -->
            <form method="post" action="">
                <table width="250">
                    <tr>
                        <td>First Name:</td>
                        <td><input type="text" name="firstname" value="<?php echo $u['FName'] ?>" /></td>
                    </tr>
                    <tr>
                        <td>Last Name:</td>
                        <td><input type="text" name="lastname" value="<?php echo $u['LName'] ?>" /></td>
                    </tr>
                    <tr>
                        <td>Username:</td>
                        <td><input type="text" name="EMail" value="<?php echo $u['EMail'] ?>" /></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="edit" value="Edit" /></td>
                    </tr>
                </table>
            </form>
        <!-- /Edit Form -->
            <?
    }
    
    // If edit was hit
    if ($_POST['edit']) {
        $firstname = $_POST['FName'];
        $lastname = $_POST['LName'];
        $username = $_POST['EMail'];
        
            // Update data
            $update = mysql_query("UPDATE `form` SET FName = '$FName', LName = '$LName', EMail = '$EMail' WHERE RegID = '$id'") or die ('Error Updating Data! <br />' .mysql_error());
            
            echo 'Update successfull';
    }
    }
    
    ?>

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

    Default

    Ok, here is what you would do to add a delete function. The first part is the delete link.
    PHP Code:
    <?php
        
    echo '<a href="index.php?act=chk_del&id='.$qry['id'].'">[X]</a>';
        
    // If delete was hit, ask for confirm
    if ($_GET[['act'] == 'chk_del') {
        
    $id $_GET['id'];
        echo 
    'Are you sure you want to delete this user? 
            <br />
        <a href="index.php?act=delete&id='
    .$id.'">Yes, delete it</a> | <a href="javascript:history.back();">Cancel</a>';
    }

    // If delete confirmed
    elseif ($_GET['act'] == 'delete') {
        
    $id $_GET['id'];
        
    $del mysql_query("DELETE FROM `form` WHERE id ='$id'") or die ('Error Deleting User! <br />' .mysql_error());
        echo 
    'The user has been deleted.
            <br />
        <a href="index.php">Back To Main</a>'
    ;
    }

    ?>
    It has a confirm delete before it actually deletes.
    As for your edit problem, I will take a look when I get home, got to be heading out at the moment.
    Hope this helps
    Thanks DD, you saved me countless times

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

    Default

    i have just tried your code above. it runs through fine, but doesnt seem to do anything. i still have the record i was deleting. see for yourself at www.beinhealth.com/form/bih.html and then click on search by last name. enter mcleod in there. you can click on edit or delete there. neither give errors, just done do the function. i am stumped

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

    Default

    here is the code i am using for all of three pages incase it is any one of them.

    first the search one
    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="edit.php?RegID='.$u['RegID'].'">Edit</a></td>
    					<td><a href="delete.php?act=chk_del&id='.$qry['RegID'].'">Delete</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');
    } 
    
    ?>

    next the edit one:
    Code:
    <?php
        require('link.php'); 
    
    // Get the user id
    $RegID = $_GET['RegID'];
    
    // Get data from user with the specified id
    $info = mysql_query("SELECT * FROM `form` WHERE RegID = '$RegID'") or die ('Error Getting User Data! <br />' .mysql_error());
    $chk = mysql_num_rows($info);
    $u = mysql_fetch_array($info);
    
    // If edit not hit
    if (!$_POST['edit']) {
    
        // If user id returns no results
        if ($chk < 1) {
            echo 'The user with the id <b>'.$RegID.'</b> does not exist!';
        }
        else {
            // Edit Form
            ?>
        <!-- Edit Form -->
            <form method="post" action="">
                <table width="250">
                    <tr>
                        <td>First Name:</td>
                        <td><input type="text" name="firstname" value="<?php echo $u['FName'] ?>" /></td>
                    </tr>
                    <tr>
                        <td>Last Name:</td>
                        <td><input type="text" name="lastname" value="<?php echo $u['LName'] ?>" /></td>
                    </tr>
                    <tr>
                        <td>Username:</td>
                        <td><input type="text" name="EMail" value="<?php echo $u['EMail'] ?>" /></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="edit" value="Edit" /></td>
                    </tr>
                </table>
            </form>
        <!-- /Edit Form -->
            <?
    }
    
    // If edit was hit
    if ($_POST['edit']) {
        $firstname = $_POST['FName'];
        $lastname = $_POST['LName'];
        $username = $_POST['EMail'];
        
            // Update data
            $update = mysql_query("UPDATE `form` SET FName = '$FName', LName = '$LName', EMail = '$EMail' WHERE RegID = '$RegID'") or die ('Error Updating Data! <br />' .mysql_error());
            
            echo 'Update successfull
     <br />
        <a href="bih.html">Back To Main</a>';
    }
    }
    
    ?>
    last the delete one:

    Code:
    <?php    
        require('link.php');
    
    // If delete was hit, ask for confirm
    if ($_GET['act'] == 'chk_del') {
        $RegID = $_GET['RegID'];
        echo 'Are you sure you want to delete this user? 
            <br />
        <a href="delete.php?act=delete&RegID='.$RegID.'">Yes, delete it</a> | <a href="javascript:history.back();">Cancel</a>';
    }
    
    // If delete confirmed
    elseif ($_GET['act'] == 'delete') {
        $RegID = $_GET['RegID'];
        $del = mysql_query("DELETE FROM `form` WHERE RegID ='$RegID'") or die ('Error Deleting User! <br />' .mysql_error());
        echo 'The user has been deleted.
            <br />
        <a href="bih.html">Back To Main</a>';
    }
    
    ?>
    man sorry for all the trouble i am causing you. i really appreciate the help though.

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

    Default

    ok, figured out the edit part. had a ] at the end instead of at the end of the first if (edit) statment. now working in delete.

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

    Default

    What you need to do is change this:
    Code:
    <a href="delete.php?act=delete&id='.$RegID.'">
    To this:
    Code:
    <a href="delete.php?act=delete&RegID='.$RegID.'">
    In your main page that displays the delete link and it should work.

    Hope this helps out.

    Also, if you don't mind, could you tell me how you got it to force the download of the text file rather than just display it? I would really like to learn that. Thanks
    Last edited by Titan85; 04-04-2007 at 08:50 PM.
    Thanks DD, you saved me countless times

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

    Default

    i will give that a try. here is what i used to export. it is your code that i just tweeked a bit. mostly changing the document type to attachment.

    PHP Code:
    <?php 
        
    require('link.php'); 
         
    // If search is active 
    if ($_POST['search']) { 
        
    $date $_POST['date']; 
         
        
    // Get results from database 
        
    $users mysql_query("SELECT * FROM `form` WHERE Date = '$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 
            
    else { 
             
                
    // Set header to download users 
              
    header("Content-type: text/plain");
              
    header("Content-disposition: attachment; filename=Registered.TXT");
                     
                
    // For each user found 
                
    while($u mysql_fetch_array($users)) { 
                 
                    
    // Show data for each user 
                    
    echo $u['FName'].'|'.$u['LName'].'|'.$u['EMail'].'|'.$u['Phone'].'|'.$u['Address'].'|'.$u['City'].'|'.$u['State'].'|'.$u['Zip'].'|'.$u['OState'].'|'.$u['Country'].'|'.$u['DOB'].'|'.$u['Occ'].'|'.$u['Meds'].'|'.$u['Married'].'|'.$u['Accom'].'|'.$u['ReadAMEW'].'|'.$u['ListenTapes'].'|'.$u['AttendSeminar'].'|'.$u['AttendWhere'].'|'.$u['Knowledge'].'|'.$u['KnowledgeHow'].'|'.$u['Issues1'].'|'.$u['Issues2'].'|'.$u['Issues3'].'|'.$u['Issues4'].'|'.$u['Comments']."\n"
                } 
                 
                
    // End table 
               
            




    // download on click
    if (!$_POST['search']) { 
        echo 
    ' <center><h2>Download Program Signups.</h2></center><br><br>
        <form method="post" action=""> 
            <b>Date:</b> <input type="text" name="Date" value="">
            <input type="submit" name="search" value="Search" /> 
        </form><br><br><br><a href="bih.html">&lt;&lt;Back</a>'




    ?>
    hope that helps you. you have been a huge help. much appreciation.

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

    Default

    still not deleting though. i am going over the code hoping to find it. if you have any other ideas..... would be much appreciated.

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

    Default

    Never mind... i got it. bah it is always the little things.

    thanks for your help. you have saved me a ton of head scratching

    brent

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

    Default

    Thanks for showing me how to make it download. Glad to hear you got it working. Was it just the link like I said or something else?
    Last edited by Titan85; 04-04-2007 at 09:33 PM.
    Thanks DD, you saved me countless times

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
  •