i have tried to write a script which does all the following on one page,
grab all my users
grab individual records
add / edit / delete these records
the script ive wrote does everything but edit, it just wont do it, ive been looking for hours to see why and ive got to the point where i just dont know or ive looked for too long i aint loking right,
i hope somebody could look over this and tell me where ie gone wrong,
here is te code:
Code: Select all
<?
include "includes/Pagination.php";
include "includes/head.html";
include "includes/theme.php";
include "includes/dbinfo.inc.php";
$title="Users";
openbody($title);
opentable();
include "includes/adminnav.php";
///////////////////checking to see if submit (edit/insert) has been clicked////////////////////////////
if ($submit) {
// here if no ID then adding else we're editing
if ($edit) {
$sql = "UPDATE members SET username='$username',password='$password', email='$email', gid='$gid'
WHERE uid=$edit";
echo $_POST["username"];?></b> has been edited.<hr noshade color="#C0C0C0" size="1">
<? echo"Click <a href="admin.php">to go back to admin section.";
} else {
$sql = "INSERT INTO members (uid, username, password, email, gid) VALUES
('$uid', '$username', '$password', '$email', '$gid')";
$result = mysql_query($sql);
echo $_POST["username"];?></b> has been added.<hr noshade color="#C0C0C0" size="1">
<? echo"Click <a href="admin.php">to go back to admin section.";
}
}
/////////grabbing a single record/////////////////////////////////////////////////////
elseif ($userid) {
$pagination = new EasyPagination($page,4,"eng");
$sqlSearch = "SELECT uid,username,email,gid FROM members WHERE uid=$userid";
$pagination->setSQLSearch($sqlSearch);
$SQLresult = $pagination->getResultData($page);
if (mysql_num_rows($SQLresult)>=1):
while (list($uid,$username,$email,$gid) = mysql_fetch_row($SQLresult)):
echo "<tr>
<td>$username</td>
<td>$email</td>
<td>$gid</td>
<td><a href="$PHPSELF?edit=$uid">Edit</td>
<td><a href="$PHPSELF?deletecheck=$uid">Delete</td>
</tr>";
endWhile;
endIf;
}
///////////////////////////////////editing a record///////////////////////////////////
elseif ($edit) {
$pagination = new EasyPagination($page,4,"eng");
$sqlSearch = "SELECT uid,username,password,email,gid FROM members WHERE uid=$edit";
$pagination->setSQLSearch($sqlSearch);
$SQLresult = $pagination->getResultData($page);
if (mysql_num_rows($SQLresult)>=1):
while (list($uid,$username,$password,$email,$gid) = mysql_fetch_row($SQLresult)):
?>
<td><form method="post" action="<? echo $PHPSELF ?>">
<input type=hidden name="uid" value="<?php echo $uid ?>">
<table border="0" width="100%">
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td background="images/ppd_15.jpg" colspan="2">
Edit <? echo $title ?></td>
</tr>
<tr>
<td width="23%">UserName: </td>
<td width="76%">
<input type="text" name="username" value="<? echo $username ?>" size="20" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080"></td>
</tr>
<tr>
<td width="23%">Password</td>
<td width="76%">
<input type="password" name="password" value="<? echo $password ?>"size="20" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080"></td>
</tr>
<tr>
<td width="23%">Email</td>
<td width="76%">
<input type="text" name="email" value="<? echo $email ?>" size="20" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080"></td>
</tr>
<tr>
<td width="23%">Group Id</td>
<td width="76%">
<input type="text" name="gid" value="<? echo $gid ?>" size="20" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080"></td>
</tr>
<tr>
<td width="99%" colspan="2">
<p align="center">
<input type="submit" name="submit" value="Edit <? echo $title ?>" style="border:1px solid #808080; font-size:10px; color:#000000; background-color:#808080"></td>
</tr>
</table>
<?
endWhile;
endIf;
}
////////////////////////////////adding a record/////////////////////////////////////
elseif ($add) {
?>
<td><form method="post" action="<? echo $PHPSELF ?>">
<input type=hidden name="uid" value="<?php echo $uid ?>">
<table border="0" width="100%">
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td background="images/ppd_15.jpg" colspan="2">
Add <? echo $title ?></td>
</tr>
<tr>
<td width="23%">UserName: </td>
<td width="76%">
<input type="text" name="username" size="20" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080"></td>
</tr>
<tr>
<td width="23%">Password</td>
<td width="76%">
<input type="password" name="password" size="20" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080"></td>
</tr>
<tr>
<td width="23%">Email</td>
<td width="76%">
<input type="text" name="email" size="20" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080"></td>
</tr>
<tr>
<td width="23%">Group Id</td>
<td width="76%">
<select size="1" name="gid" style="font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #808080">
<option>1</option>
<option selected>2</option>
<option>3</option>
</select></td>
</tr>
<tr>
<td width="99%" colspan="2">
<p align="center">
<input type="submit" name="submit" value="Add <? echo $title ?>" style="border:1px solid #808080; font-size:10px; color:#000000; background-color:#808080"></td>
</tr>
</table>
<?
}
///////////////////////////////deleting a record////////////////////////////////////
elseif ($deletecheck) {
$sql = "SELECT * FROM members WHERE uid=$deletecheck";
$result = mysql_query($sql);
echo"<td>Are you sure you want to delete this $title? <td><a href="$PHPSELF?delete=$deletecheck"> Yes</a></td><td><a href="$PHPSELF?edit=$uid"> No</a></td>";
}
elseif ($delete) {
$sql = "DELETE FROM members WHERE uid=$delete";
$result = mysql_query($sql);
echo "<td>$sql Record deleted! Click <a href="admin.php">here</a> to go back to admin section.<p>";
}
/////////////////////////////main page/////////////////////////////////////////////
else {
if ($_GET["page"]!=""): $page = $_GET["page"]; else: $page = 1; endif;
$pagination = new EasyPagination($page,4,"eng");
$sqlSearch = "SELECT uid,username,email,gid FROM members";
$pagination->setSQLSearch($sqlSearch);
$sqlNumRows = "SELECT COUNT(uid) AS numTotal FROM members";
$pagination->setSQLNumRows($sqlNumRows);
$SQLresult = $pagination->getResultData($page);
echo "Page: <font color='#CCCC66'>$page</font> >> Showing: ".$pagination->getListCurrentRecords()."<br>";
echo "Result: <font color='#CCCC66'>".$pagination->getTotalRecords()."</font> occurrence(s) in <font color='#CCCC66'>".$pagination->getPagesFound()."</font> page(s)<br>";
echo "<br>";
echo $pagination->getNavigation()."<br><br>";
echo $pagination->getCurrentPages();
echo "<br><br>";
echo $pagination->getNavigationGroupLinks();
if (mysql_num_rows($SQLresult)>=1):
echo"<td colspan=3><a href="$PHPSELF?add=1">Add new $title<hr></td>";
?><td colspan=3><?
while (list($uid,$username,$email,$gid) = mysql_fetch_row($SQLresult)):
echo "<tr>
<td><a href="$PHPSELF?userid=$uid">$username</td>
<td>$email</td>
<td>$gid</td>
</tr>";
endWhile;
endIf;
}
closetable();
closebody();
include "includes/footer.html";
?>