Log in

View Full Version : Changing Data In MySQL Through PHP



tomyknoker
03-15-2007, 02:53 PM
Hi,

I have the following php page, it displays my members, by there Status... Approved, Deleted, On Hold etc... I want to add a 'Delete' next to each member in the table that gets displayed, but only want this 'Delete' button to move the members to the 'Delete' column. Which from a database POV would mean changing the member in the 'MemApp' column from an 'A' to a 'D'... Any help would be greatly appreciated!



/* set the allowed order by columns */
$default_sort = 'LastName';
$allowed_order = array ('JoinDate', 'FirstName','LastName', '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'];
}

/* 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 "<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_order)) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&cat=$cat\">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD>\n";
}
echo "</TR>\n";

/* reset the $result set back to the first row and
* display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
echo "<TD>$column</TD>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";
?>

thetestingsite
03-16-2007, 01:27 AM
Something like this?



<?php
/* set the allowed order by columns */
$default_sort = 'LastName';
$allowed_order = array ('JoinDate', 'FirstName','LastName', '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'];

$info = mysql_query("SELECT * FROM tblmembers WHERE `UserID`='$del'");
$q = mysql_fetch_array($info);

$username = $q['username'];

mysql_query("INSERT INTO `deleted` (`id`,`username`,`userid`) VALUES ('null', '$username', '$del')");

mysql_query("DELETE FROM `tblmembers` 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 "<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_order)) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&cat=$cat\">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD> <td>Delete?</td>\n";
}
echo "</TR>\n";

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

mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
echo "<TD>$column</TD>
<td><a href=\"{$_SERVER['PHP_SELF']}?del=".$column['id']."&act=del\">Delete User</a></td>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";

}
?>


That will insert the username, and userid of the selected user into a "deleted" database table. Then it will delete the original record from the tblmembers table.

Let me know if you need to modify it a little more. Hope this helps.

tomyknoker
03-16-2007, 01:33 AM
Ok looks great, yea I think what I initially want to happen is say you look at the Approved members, on each members line in the table I want to have a 'Delete' link, if that's clicked, I just want to make the user from a value 'A' to value 'P', that way they aren't deleted as such and they still are in tblmembers table, they just have 'D' = 'Deleted' as there status... You know what I mean?

tomyknoker
03-16-2007, 01:51 AM
Ok looks great, yea I think what I initially want to happen is say you look at the Approved members, on each members line in the table I want to have a 'Delete' link, if that's clicked, I just want to make the user from a value 'A' to value 'P', that way they aren't deleted as such and they still are in tblmembers table, they just have 'D' = 'Deleted' as there status... You know what I mean?

thetestingsite
03-16-2007, 01:59 AM
Then you would want something like this:



<?php
/* set the allowed order by columns */
$default_sort = 'LastName';
$allowed_order = array ('JoinDate', 'FirstName','LastName', '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 "<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_order)) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&cat=$cat\">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD> <td>Delete?</td>\n";
}
echo "</TR>\n";

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

mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
echo "<TD>$column</TD>
<td><a href=\"{$_SERVER['PHP_SELF']}?del=".$column['id']."&act=del\">Delete User</a></td>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";

}
?>


Hope this helps.

tomyknoker
03-16-2007, 02:06 AM
Ok great well it loads, I haven't tested the 'Delete' yet, just 2 questions, it displays 'Delete User' for every field how can I fix that?
ID Delete? FirstName Delete? LastName Delete? DateOfBirth Delete? Gender Delete? PhoneNumber Delete? MobileNumber Delete? Email Delete? Address Delete? Suburb Delete? City Delete? State Delete? Country Delete? PostCode Delete? MembershipLevel Delete? GeographicalTerritory Delete? PreferredContact Delete? HearAboutUs Delete? PreviousMember Delete? PreviousMemberNumber Delete? OnlineOffers Delete? CocktailCompetitions Delete? RSA Delete? PreviousBarTraining Delete? YearsExperience Delete? CareerStep Delete? CocktailList Delete? JoinDate Delete? MemberApproved Delete? UserName Delete? Password Delete? RemovedDate Delete? rep_NBR Delete? loginDateTime Delete?
193 Delete User Kevin Delete User Clark Delete User 1977-02-27 Delete User M Delete User

AND

How do I just get it to show user's FirstName, LastName, PhoneNumber, MobileNumber, Email, City, State, JoinDate, MemberApproved, loginDateTime... And if possible the email to be an email link and also to keep the date as D/M/Y... Thanks for all your help so far!

tomyknoker
03-16-2007, 02:10 AM
Arg, I also want to have an 'Edit', next to 'Delete' for each user... And when that's clicked I wanted a drop down menu to appear which contains 'Approved', 'On Hold', 'Deleted' etc. So say I'm on the 'Approved' list and I want to make one of the members back 'On Hold' I click edit in their table row, select 'On Hold', then submit and it send them to 'On Hold' or whatever is selected...

thetestingsite
03-16-2007, 02:27 AM
<?php
/* 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 ($result, 0);
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";

}
?>


Not sure how well this will work (or if it even will), but hope this helps nonetheless.

tomyknoker
03-16-2007, 01:57 PM
Hiya! Ok I tried it and got an error which was
Parse error: parse error, expecting `','' or `';'' in e:\showMembers.php on line 117
PHP Parse error: parse error, expecting `','' or `';'' in e:\showMembers.php on line 117... Line 117 is this one
obj = document.getElementById('edit_'+id);

thetestingsite
03-16-2007, 03:47 PM
Sorry, forgot to escape the quotes. Fixed it in the code I posted above, but you can simply replace that line with this:



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

tomyknoker
03-19-2007, 12:50 AM
Thanks I didin't even see your post until now!

tomyknoker
03-19-2007, 12:54 AM
Heya... Hmm it through out an error on this line
<td>Edit</td>

thetestingsite
03-29-2007, 01:00 AM
The only thing that I could see that would cause an error would be this line:



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


this should be like so:



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


Hope this helps

tomyknoker
03-29-2007, 01:03 AM
Strange it still spits out the same error on line 149...

thetestingsite
03-29-2007, 01:25 AM
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.

tomyknoker
03-29-2007, 01:27 AM
Oh no really? I must have done something wrong then... OK here it it



<?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 ($result, 0);
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";

}
?>

thetestingsite
03-29-2007, 01:31 AM
Try changing:



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


to:



echo "<td>Edit</td>";
echo "<td>Delete</td>";


That should fix the error. Hope this helps.

tomyknoker
03-29-2007, 01:39 AM
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...

thetestingsite
03-29-2007, 02:50 AM
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:



<?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,

tomyknoker
03-29-2007, 02:58 AM
Thanks again, doesn't like this line although I can't understand why
<td><?=$q['Email';?></td>

thetestingsite
03-29-2007, 03:12 AM
Found the problem and editted the code I posted above. The edit is the part in red. That should fix it.

Hope this helps.

tomyknoker
03-29-2007, 03:21 AM
Sorry I should have mentioned I spotted that and fixed it earlier, this is the error



Parse error: parse error, expecting `']'' in \showMembers.php on line 158


I don't know if this helps but I can see a few yellow errors in dw when I look at it, it says </div> on line 150, </td> on line 151 and also </tr> on line 164... The dw error is MarkUp invalid because it's an overlapping or unclosed tag. But looked through it and they look fine to me could just be Dreamweaver being painful...

thetestingsite
03-29-2007, 03:28 AM
Here it is, it is on this line, again editted the code I posted. Sorry about the miss.



<td><?=$q['Email'];?></td>

tomyknoker
03-29-2007, 03:48 AM
Hi there... Damn it I missed that! :)

It doesn't like the last line the ?> closing tag...

thetestingsite
03-29-2007, 03:53 AM
ok, that's it. I think it is time for bed. Try adding the part in red to these lines:



if (empty($_GET['order'])) {
$order = LastName;
}
else {
$order = $_GET['order'];
}


Also editted the code that has been causing these errors. Sorry, but I'm getting offline to get ready for bed. Anyways, hope this helps.

thetestingsite
03-30-2007, 02:47 AM
Ok, I editted the code once again according to your screenshot. This should do it, but if not, let me know.



<?php

if ($_GET['cat'] == "") {
$cat = "A"; //set this to your default category
}

else {
$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"]);
}

elseif ($_REQUEST['act'] == "edit") {
$id = $_REQUEST['id'];
$status = $_REQUEST['status'];

mysql_query("UPDATE `tblmembers` SET `status`='$status' WHERE `userID`='$id'");

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="?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>';
}
?>


Hope this helps.

tomyknoker
03-30-2007, 02:51 AM
Strange still just displays the 2 members...

thetestingsite
03-30-2007, 02:55 AM
I'm wondering if this has to do with the category (or member status) not being set in the script. Try my edit in my post above (the part in red at the very top). If that doesn't work, send me a screenshot of what is happening and I'll see what I can do.

Hope this helps.

tomyknoker
03-30-2007, 03:26 AM
Well that has fixed that part great! It displays all, but the edit doesn't work or delete...

thetestingsite
03-30-2007, 03:52 AM
ok, added another part in red in the above posted code. Hope this helps.

tomyknoker
03-30-2007, 03:56 AM
Hiya ok I received a parse error I tried to see what it was but couldn't I'm probably going blind!



mysql_query("UPDATE `tblmembers` SET `status`='$status' WHERE `userID`='$id'");

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

else {

thetestingsite
03-30-2007, 03:58 AM
Hiya ok I received a parse error I tried to see what it was but couldn't I'm probably going blind!



mysql_query("UPDATE `tblmembers` SET `status`='$status' WHERE `userID`='$id'");

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

else {


What's the parse error?

tomyknoker
03-31-2007, 01:43 AM
Hiya a parse error I can't seem to find it ug!



Parse error: parse error, expecting `']'' in e:\showMembers.php on line 94
PHP Parse error: parse error, expecting `']'' in e:\showMembers.php on line 94

thetestingsite
03-31-2007, 01:46 AM
That has to do with this line:



elseif ($_REQUEST['act'] == "edit") {
$id = $_REQUEST['id'];
$status = $_REQUEST['status'];


I forgot about the quote. Hope this helps.

tomyknoker
03-31-2007, 01:57 AM
Ahhhhh great! For some reason the loginDateTime are all equal to 1-1-1970, I can understand that happening for users who haven't logged in yet but all the Approved users are equal to that... I added this line


<?php echo date('d-m-Y', $q['loginDateTime']):'unknown';?> but this gives me the following error



Parse error: parse error, expecting `','' or `';'' in e:\showMembers.php on line 179
PHP Parse error: parse error, expecting `','' or `';'' in e:\showMembers.php on line 179

thetestingsite
03-31-2007, 02:01 AM
This:



<?php echo date('d-m-Y', $q['loginDateTime']):'unknown';?>


makes no sense. Does your loginDateTime column (in your database) have the values as a unix timestamp (like 1175581024), or is it text (Jan 12, 2008)? If the first, then this should work:



<?php echo date('d-m-Y', $q['loginDateTime']);?>


Otherwise, try using this:



<?php echo date('d-m-Y', strtotime($q['loginDateTime']));?>


Hope this helps.

tomyknoker
03-31-2007, 02:10 AM
Hiya, in the database the fields look like this

I added this code as I had this before, what it did was displayed the date/time a user had logged in and if they hadn't logged in since I added the loginDateTime column to the datatabase that field in the table was just populated with 'unknown'... But they are all unknown and looking into the datatbase I can see quite a few that have logged in



<?php echo($qry['loginDateTime']?date('d/m/Y H:i:s', strtotime($qry['loginDateTime'])):'unknown') ?>

thetestingsite
03-31-2007, 02:14 AM
What if you just do:


<?php echo $qry['loginDateTime'];?>


See what it displays (if anything) and if you would like, go ahead and send me a screenshot. Not sure what else there is to say, but the code that is posted in one of my posts above should work.

Hope this helps.

tomyknoker
03-31-2007, 02:43 AM
I sent you the screenshot, my very original page before all the sorting had that code too and it worked, It's wierd... Could it be to do with the sort feature?