iarp Posted May 1, 2008 Share Posted May 1, 2008 Hey, This is the page's full code. <?php # Script 7.4 - view_users.php //retrieves all records from the users table session_name ('MOHA'); session_start(); // Start the session. $page_title = 'View Users'; include('../includes/header.php'); //page header /* if ($userlevel >= "9"){ */ echo '<h1 id="mainhead">Registered Users</h1>'; require_once('../includes/mysql_connect.php'); //display number of records $display = PAGE_DISPLAY; //determine how many pages there are if (isset($_GET['np'])) { //already been determined $num_pages = $_GET['np']; } else {// need to determine //count number of records $query = "SELECT COUNT(*) FROM " . TBL_USERS . " ORDER BY reg_date ASC"; $result = mysql_query($query); $row=mysql_fetch_array($result, MYSQL_NUM); $num_records = $row[0]; //calculate the number of pages if ($num_records > $display) { $num_pages = ceil($num_records/$display); } else { $num_pages = 1; } }//end of np if //determine where in the database to start returning results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } //default column links. $link1 = "{$_SERVER['PHP_SELF']}?sort=lna"; $link2 = "{$_SERVER['PHP_SELF']}?sort=fna"; $link3 = "{$_SERVER['PHP_SELF']}?sort=dra"; $link4 = "{$_SERVER['PHP_SELF']}?sort=una"; $link5 = "{$_SERVER['PHP_SELF']}?sort=ara"; //determine the sorting order if (isset($_GET['sort'])) { //use existing sorting order. switch ($_GET['sort']) { case 'lna': $order_by = 'last_name ASC'; $link1 = "{$_SERVER['PHP_SELF']}?sort=lnd"; break; case 'lnd': $order_by = 'last_name DESC'; $link1 = "{$_SERVER['PHP_SELF']}?sort=lna"; break; case 'fna': $order_by = 'first_name ASC'; $link2 = "{$_SERVER['PHP_SELF']}?sort=fnd"; break; case 'fnd': $order_by = 'first_name DESC'; $link2 = "{$_SERVER['PHP_SELF']}?sort=fna"; break; case 'dra': $order_by = 'registration_date ASC'; $link3 = "{$_SERVER['PHP_SELF']}?sort=drd"; break; case 'drd': $order_by = 'reg_date DESC'; $link3 = "{$_SERVER['PHP_SELF']}?sort=dra"; break; case 'una': $order_by = 'username ASC'; $link4 = "{$_SERVER['PHP_SELF']}?sort=una"; break; case 'dna': $order_by = 'username DESC'; $link4 = "{$_SERVER['PHP_SELF']}?sort=und"; break; case 'ara': $order_by = 'userlevel ASC'; $link5 = "{$_SERVER['PHP_SELF']}?sort=ara"; break; case 'ard': $order_by = 'userlevel DESC'; $link5 = "{$_SERVER['PHP_SELF']}?sort=ard"; break; default: $order_by = 'reg_date DESC'; break; } $sort = $_GET['sort']; } else { $order_by = 'reg_date ASC'; $sort = 'drd'; } //make the query $query = "SELECT username, first_name, last_name, email, userlevel, active, DATE_FORMAT(reg_date, '%M %d %Y') AS dr, user_id FROM " . TBL_USERS . " ORDER BY $order_by LIMIT $start, $display"; $result = mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); $num = mysql_num_rows($result); if ($num > 0) { //if it ran ok display the records if ($_GET['activated'] == TRUE){ echo "<div style=\"background-color: #FFFF00\"><h1>Account Activated!</h1></div>"; } echo "<p>There are currently $num_records registered users.</p>\n"; //table header echo '<table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="' . $link4 . '">Username</a></b></td> <td align="left"><b><a href="' . $link2 . '">First Name</a></b></td> <td align="left"><b><a href="' . $link1 . '">Last Name</a></b></td> <td align="left"><b>E-mail Address</b></td> <td align="left"><b><a href="' . $link5 . '">User Level</b></td> <td align="left"><b><a href="' . $link3 . '">Date Registered</a></b></td> <td align="left"><b>Notes</b></td> </tr>'; //Fetch and print all the records $bg = '#eeeeee'; // set the background color while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee'); // switch the background color echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user.php?id=' . $row['id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['id'] . '">Delete</a></td> <td align="left">' . $row['username'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['email'] . '</td> <td align="left">'; if ($row['userlevel'] == "2"){echo "User";} else if($row['userlevel'] == "9") {echo "Admin";} else if($row['userlevel'] == "10"){echo "System Admin";} else { echo "Fix this person User Level";} echo '</td> <td align="left">' . $row['dr'] . '</td> <td align="left">'; if ($row['active'] != ""){echo "<a href=\"edit_user.php?id=" . $row['user_id'] . "&activated=TRUE\">Activate!</a>";} echo ' </tr>'; } echo '</table>'; //free up the query resources mysql_free_result($result); } else { // if it didn't run ok echo '<p class="error">There are currently no registered users.</p>'; } //close the connection mysql_close(); //make the links ot other pages, if needed. if ($num_pages > 1) { echo '<br /><p>'; //determine what page the script is on. $current_page = ($start/$display) + 1; //if its not on the first page, make a previous button. if ($current_page != 1) { echo ' <a href="view_users.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> '; } //make all the number pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo ' <a href="view_users.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort . '">' . $i . '</a> '; } else { echo $i . ' '; } } //if it's not the last page, make a Next button. if ($current_page != $num_pages) { echo ' <a href="view_users.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort . '">Next</a> '; } echo '</p>'; }// enf of links section include('../includes/footer.php'); /*} else { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST']; // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/login.php'; header("Location: $url"); exit(); // Quit the script. }*/ ?> I added or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); in a vein attempt to find out what's wrong and i now get this error: Query: SELECT username, first_name, last_name, email, userlevel, active, DATE_FORMAT(reg_date, '%M %d %Y') AS dr, user_id FROM users ORDER BY reg_date ASC LIMIT 0, PAGE_DISPLAY MySQL Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'PAGE_DISPLAY' at line 1 in /homepages/31/d204952132/htdocs/iarp/admin/view_users.php on line 112 So hopefully this is what's going wrong with the page and my supposed "ghost" in the database. I've looked through this code and as far into php as i am i don't see anything wrong. This code is running on my main website in which i just copied and pasted from my test website to my main and still got the same error. Hopefully someone can see this error that i've made somewhere. Link to original post with my problems http://www.phpfreaks.com/forums/index.php/topic,193538.0.html Quote Link to comment https://forums.phpfreaks.com/topic/103767-update-ghost-in-my-database/ Share on other sites More sharing options...
peranha Posted May 1, 2008 Share Posted May 1, 2008 $display has to be a number, not the words PAGE_DISPLAY Quote Link to comment https://forums.phpfreaks.com/topic/103767-update-ghost-in-my-database/#findComment-531272 Share on other sites More sharing options...
iarp Posted May 2, 2008 Author Share Posted May 2, 2008 Thank-you, that fixed that page. For my original problem, i went with something simple: <?php include ('../includes/header.php'); include_once('../includes/mysql_connect.php'); $query = "SELECT COUNT(*) FROM " . TBL_USERS . " WHERE active != NULL"; $result = mysql_query($query); $num = mysql_num_rows($result); echo "Number of accounts that don't have <i>NULL</i> for active: " . $num; include('../includes/footer.php'); ?> Dunno about you but i thought that was pretty simple. There's 2 users in the database both, for the active field have been set to NULL. In phpMyAdmin the check box for null is checked just to make sure. Run the script on http://www.iarp.ca/admin/index.php and you can see it shows 1! Quote Link to comment https://forums.phpfreaks.com/topic/103767-update-ghost-in-my-database/#findComment-531434 Share on other sites More sharing options...
sasa Posted May 2, 2008 Share Posted May 2, 2008 use $num = mysql_result($result,0); Quote Link to comment https://forums.phpfreaks.com/topic/103767-update-ghost-in-my-database/#findComment-531528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.