Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 39

Thread: Changing Data In MySQL Through PHP

  1. #11
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks I didin't even see your post until now!

  2. #12
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Heya... Hmm it through out an error on this line
    PHP Code:
    <td>Edit</td

  3. #13
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The only thing that I could see that would cause an error would be this line:

    Code:
    <div id=\"edit_".$column['id']."\" style="display: none;">
    this should be like so:

    Code:
    <div id=\"edit_".$column['id']."\" style=\"display: none;\">
    Hope this helps
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #14
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Strange it still spits out the same error on line 149...

  5. #15
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well, the code I posted only goes has 122 lines. Please post the code that you have so that we can see what line is (and what is around line) 149 that could be causing this error.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #16
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh no really? I must have done something wrong then... OK here it it

    PHP Code:
    <?php
    $cat 
    $_GET['cat'];

    /* connect to the mysql database and use a query to get the members info */

    include 'library/config.php';
    include 
    'library/opendb.php';

    //navigation
    include("nav.php");

    //approved
    $a mysql_query("SELECT * FROM `tblmembers` WHERE `MemberApproved`='A'");
    $aCount mysql_num_rows($a);

    //deleted
    $d mysql_query("SELECT * FROM `tblmembers` WHERE `MemberApproved`='D'");
    $dCount mysql_num_rows($d);

    //on hold
    $h mysql_query("SELECT * FROM `tblmembers` WHERE `MemberApproved`='H'");
    $hCount mysql_num_rows($h);

    //pending
    $p mysql_query("SELECT * FROM `tblmembers` WHERE `MemberApproved`='P'");
    $pCount mysql_num_rows($p);

    //not sure
    $n mysql_query("SELECT * FROM `tblmembers` WHERE `MemberApproved`='N'");
    $nCount mysql_num_rows($n);

    //rejected
    $r mysql_query("SELECT * FROM `tblmembers` WHERE `MemberApproved`='R'");
    $rCount mysql_num_rows($r);

    if (
    $cat == "a") {
    $field "Approved";
    $theCount $aCount;
    }

    elseif (
    $cat == "d") {
    $field "Deleted";
    $theCount $dCount;
    }

    elseif (
    $cat == "h") {
    $field "On Hold";
    $theCount $hCount;
    }

    elseif (
    $cat == "p") {
    $field "Pending";
    $theCount $pCount;
    }

    elseif (
    $cat == "n") {
    $field "Not Sure";
    $theCount $nCount;
    }

    elseif (
    $cat == "r") {
    $field "Rejected";
    $theCount $rCount;
    }

    echo 
    'There are '.$theCount.' members that are '.$field;

    /* set the allowed order by columns */
    $default_sort 'LastName';
    $allowed_order = array ('JoinDate''FirstName','LastName''loginDateTime');

    $allowed_display = array('FirstName''LastName''PhoneNumber''MobileNumber''Email''City''State''JoinDate''MemberApproved''loginDateTime');

    /* if order is not set, or it is not in the allowed
     * list, then set it to a default value. Otherwise, 
     * set it to what was passed in. */
    if (!isset ($_GET['order']) || 
        !
    in_array ($_GET['order'], $allowed_order)) {
        
    $order $default_sort;
    } else {
        
    $order $_GET['order'];
    }


    if (
    $_REQUEST['act'] == "del") {

    $del $_REQUEST['del'];
     
    mysql_query("UPDATE `tblmembers` SET `status`='D' WHERE `userID`='$del'");


    header('Location: '.$_SERVER["PHP_SELF"]);
    }

    else {



    /* construct and run our query */
    $query "SELECT * FROM tblmembers WHERE `MemberApproved`='$cat' ORDER BY $order";

    $result mysql_query ($query);

    /* make sure data was retrieved */
    $numrows mysql_num_rows($result);
    if (
    $numrows == 0) {
        echo 
    "No data to display!";
        exit;
    }

    /* now grab the first row and start the table */
    $row mysql_fetch_assoc ($result);

    echo 
    '<script type="text/javascript">
    function showForm(id) {

    obj = document.getElementById(\'edit_\'+id);

     if (obj.style.display == "none") {
         obj.style.display = "";
     }

     else {
         obj.style.display = "none";
     }
    }
    </script>
    '
    ;

    echo 
    "<TABLE border=1>\n";
    echo 
    "<TR>\n";

    foreach (
    $row as $heading=>$column) {
        
    /* check if the heading is in our allowed_order
         * array. If it is, hyperlink it so that we can
         * order by this column */
        
    echo "<TD><b>";

     if (
    in_array($heading$allowed_display)) {
        if (
    in_array ($heading$allowed_order)) {
            echo 
    "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&cat=$cat\">$heading</a>";
        } else {
            echo 
    $heading;
        }                
        echo 
    "</b></TD>\n";
     }
    }

    <
    td>Edit</td>
    <
    td>Delete</td>

    echo 
    "</TR>\n";

    /* reset the $result set back to the first row and 
     * display the data */

    mysql_data_seek ($result0);
    while (
    $row mysql_fetch_assoc ($result)) {
        echo 
    "<TR>\n";
        foreach (
    $row as $column) {
            echo 
    "<TD>$column</TD>
    <td><a href=\"#\" onclick=\"showForm('"
    .$column['id']."'); return false;\">Edit</a>

    <div id=\"edit_"
    .$column['id']."\" style=\"display: none;\">
    <!--status form-->

    <form method=\"POST\" action=\"
    {$_SERVER['PHP_SELF']}\">
    <input type=\"hidden\" name=\"act\" value=\"edit\">
    <input type=\"hidden\" name=\"id\" value=\""
    .$column['id']."\">

    <select name=\"status\">
    <option value=\"A\">Approved</option>
    <!--enter options for status menu-->
    </select>

    </div>

    </td>

    <td><a href=\"
    {$_SERVER['PHP_SELF']}?del=".$column['id']."&act=del\">Delete User</a></td>\n";
        }
        echo 
    "</TR>\n";
    }
    echo 
    "</TABLE>\n";

    }
    ?>

  7. #17
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try changing:

    Code:
    <td>Edit</td>
    <td>Delete</td>
    to:

    Code:
    echo "<td>Edit</td>";
    echo "<td>Delete</td>";
    That should fix the error. Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #18
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cool thatworked, but it's gone a little crazy. It still displays every single column in the 'tblmembers' table... And also next to every single column it adds the 'Edit' and 'Delete' link... When I clicked on the 'Edit' link it only gave me the option of 'Approved'.... I PM'ed you a little snapshot, I thought it might give you a better understanding of what is happening...

  9. #19
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    After looking at the screenshot, I figured it was time to rewrite the eintire code. Probably not as effective as some would write it, but still does what you want it to do. Below is the code:

    Code:
    <?php
    $cat = $_GET['cat'];
    
    /* connect to the mysql database and use a query to get the members info */
    
    include 'library/config.php';
    include 'library/opendb.php';
    
    //navigation
    include("nav.php");
    
    //approved
    $aCount = mysql_query("SELECT COUNT(*) FROM `tblmembers` WHERE `MemberApproved`='A'");
    
    //deleted
    $dCount = mysql_query("SELECT COUNT(*) FROM `tblmembers` WHERE `MemberApproved`='D'");
    
    //on hold
    $hCount = mysql_query("SELECT COUNT(*) FROM `tblmembers` WHERE `MemberApproved`='H'");
    
    //pending
    $pCount = mysql_query("SELECT COUNT(*) FROM `tblmembers` WHERE `MemberApproved`='P'");
    
    //not sure
    $nCount = mysql_query("SELECT COUNT(*) FROM `tblmembers` WHERE `MemberApproved`='N'");
    
    //rejected
    $rCount = mysql_query("SELECT COUNT(*) FROM `tblmembers` WHERE `MemberApproved`='R'");
    
    if ($cat == "a") {
    $field = "Approved";
    $theCount = $aCount;
    }
    
    elseif ($cat == "d") {
    $field = "Deleted";
    $theCount = $dCount;
    }
    
    elseif ($cat == "h") {
    $field = "On Hold";
    $theCount = $hCount;
    }
    
    elseif ($cat == "p") {
    $field = "Pending";
    $theCount = $pCount;
    }
    
    elseif ($cat == "n") {
    $field = "Not Sure";
    $theCount = $nCount;
    }
    
    elseif ($cat == "r") {
    $field = "Rejected";
    $theCount = $rCount;
    }
    
    echo 'There are '.$theCount.' members that are '.$field;
    
    /* if order is not set, or it is not in the allowed
     * list, then set it to a default value. Otherwise, 
     * set it to what was passed in. */
    
    if (empty($_GET['order'])) {
    $order = 'LastName';
    }
    else {
    $order = $_GET['order'];
    }
    
      if ($_REQUEST['act'] == "del") {
    
    $del = $_REQUEST['del'];
     
    mysql_query("UPDATE `tblmembers` SET `status`='D' WHERE `userID`='$del'");
    
    
    header('Location: '.$_SERVER["PHP_SELF"]);
      }
    
      else {
    
    
    
    /* construct and run our query */
    $query = "SELECT * FROM tblmembers WHERE `MemberApproved`='$cat' ORDER BY `$order`";
    
    $result = mysql_query ($query);
    
    /* make sure data was retrieved */
    $numrows = mysql_num_rows($result);
    if ($numrows == 0) {
        echo "No data to display!";
        exit;
    }
    
    
    echo '<script type="text/javascript">
    function showForm(id) {
    
    obj = document.getElementById(\'edit_\'+id);
    
     if (obj.style.display == "none") {
         obj.style.display = "";
     }
    
     else {
         obj.style.display = "none";
     }
    }
    </script>
    
    
    <table border="1">
     <tr>
      <td> &nbsp;</td>
      <td> &nbsp;</td>
      <td><a href="?order=FirstName">FirstName</a></td>
      <td><a href="?order=LastName">LastName</a></td>
      <td><a href="?order=PhoneNumber">PhoneNumber</a></td>
      <td><a href="?order=MobileNumber">MobileNumber</a></td>
      <td><a href="?order=Email">Email</a></td>
      <td><a href="?order=City">City</a></td>
      <td><a href="?order=State">State</a></td>
      <td><a href="?order=JoinDate">JoinDate</a></td>
      <td><a href="?order=MemberApproved">MemberApproved</a></td>
      <td><a href="?order=loginDateTime">loginDateTime</a></td>
     </tr>';
    
    /* Now display the data */
     while ($q = mysql_fetch_array($result)) {
    ?>
     <tr>
       <td><a href="#" onclick="showForm(' <?php echo $q['id'];?>'); return false;">Edit</a>
    
    <div id="edit_<?php echo $q['id'];?>" style="display: none;">
    <!--status form-->
    
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <input type="hidden" name="act" value="edit">
    <input type="hidden" name="id" value="<?php echo $q['id'];?>">
    
    <select name="status">
    <option value="A">Approved</option>
    <!--enter options for status menu-->
    </select>
    
    </div>
       </td>
    
       <td><a href="<?php echo $_SERVER['PHP_SELF'];?>?del=<?php echo $q['id'];?>&act=del">Delete User</a></td>
      <td><?=$q['FirstName'];?></td>
      <td><?=$q['LastName'];?></td>
      <td><?=$q['PhoneNumber'];?></td>
      <td><?=$q['MobileNumber'];?></td>
      <td><?=$q['Email'];?></td>
      <td><?=$q['City'];?></td>
      <td><?=$q['State'];?></td>
      <td><?php echo date('d-m-Y', strtotime($q["JoinDate"]));?></td>
      <td><?=$q['MemberApproved'];?></td>
      <td><?php echo date('d-m-Y', $q['loginDateTime']);?></td>
     </tr>
    <?php
     }
     
    echo '</table>';
    }
    ?>
    As for the other thing (the edit only showing "Approved"), you have to add the other itemds to the select box (where I put <!--enter options for status menu-->).

    Hope this helps,
    Last edited by thetestingsite; 03-30-2007 at 02:47 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #20
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks again, doesn't like this line although I can't understand why
    PHP Code:
      <td><?=$q['Email';?></td>

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
  •