iarp Posted April 21, 2008 Share Posted April 21, 2008 I originally had: $query1 = "SELECT COUNT(*) FROM " . DB_USERS . " WHERE active != NULL"; $result1 = @mysql_query($query1); $user_activate = mysql_num_rows($result1); if ($user_activate > 0) echo "<p><a href=\"view_users.php\">There seems to be $user_activate person awaiting activation</a></p>"; But even thought i was on the database admin page and theres only 3 users, all 3 are set to NULL. Yet the output on the page says theres 1 person awaiting activation So i tried the code below to show just whatis equaling this 1 "person" and got... $query1 = "SELECT * FROM " . DB_USERS . " WHERE active != NULL"; $result1 = @mysql_query($query1); $user_activate = mysql_num_rows($result1); if ($user_activate >= 0) echo "<p><a href=\"view_users.php\">There seems to be' $result 'person awaiting activation</a></p>"; Returns: There seems to be' Resource id #6 'person awaiting activation Is there such a thing as database ghosts ? Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/ Share on other sites More sharing options...
Gamic Posted April 21, 2008 Share Posted April 21, 2008 This might help you better track down what is going on: <?php $query1 = "SELECT * FROM " . DB_USERS . " WHERE active != NULL"; $result1 = @mysql_query($query1); $user_activate = mysql_num_rows($result1); $br="<br />\n"; if ($user_activate >= 0) { //foreach row in the result set while($row=mysql_fetch_array($result1,MYSQL_ASSOC){ //for each field in the row foreach ($row as $key=>$value){ echo "$key : $value $br"; } } //echo "<p><a href=\"view_users.php\">There seems to be' $result 'person awaiting activation</a></p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-522682 Share on other sites More sharing options...
iarp Posted April 21, 2008 Author Share Posted April 21, 2008 Nothing shows up lol. Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-522770 Share on other sites More sharing options...
jonsjava Posted April 21, 2008 Share Posted April 21, 2008 <?php $query1 = "SELECT * FROM " . DB_USERS . " WHERE active != NULL"; $result1 = @mysql_query($query1); $user_activate = mysql_num_rows($result1); $usernames = array(); if ($user_activate >= 0) { while ($user_check = mysql_fetch_assoc($result1)){ $usernames[] .= $user_check['username']; //change to what the username field is on your db } echo "<p><a href=\"view_users.php\">Accounts awaiting activation: "; foreach ($usernames as $value){ print $value.", "; } echo "</a></p>"; } this will echo all the users awaiting activation Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-522820 Share on other sites More sharing options...
iarp Posted April 21, 2008 Author Share Posted April 21, 2008 tried that and all i got was Accounts awaiting activation nothing else, so then i went and deactivated someone which should've triggered this to work, and all i got was the exact same thing. The username isn't printing at all with it. Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-522832 Share on other sites More sharing options...
jonsjava Posted April 21, 2008 Share Posted April 21, 2008 Try this (slightly modified query. change variable to suit your needs) <?php $query1 = "SELECT * FROM `{$DB_USER}` WHERE `active` != NULL;"; $result1 = @mysql_query($query1); $user_activate = mysql_num_rows($result1); $usernames = array(); if ($user_activate >= 0) { while ($user_check = mysql_fetch_assoc($result1)){ $usernames[] .= $user_check['username']; //change to what the username field is on your db } echo "<p><a href=\"view_users.php\">Accounts awaiting activation: "; foreach ($usernames as $value){ print $value.", "; } echo "</a></p>"; } Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-522839 Share on other sites More sharing options...
iarp Posted April 21, 2008 Author Share Posted April 21, 2008 i changed if ($user_activate >= 0) { to if ($user_activate > 0) { Because having the code execute even if theres 0 there doesn't make sence. The code now doesn't run at all even though i have 1 person that is not set to NULL. So now i'm wondering if theres something else wrong. Just above this piece of coding i have: $query = "SELECT approved FROM " . DB_URLS . " WHERE approved = 'N'"; $result = @mysql_query($query); $link_app = mysql_num_rows ($result); if ($link_app > 0) echo "<p> <a href=\"edit_url.php\">You have $link_app link(s) waiting on approval</a></p>"; Link to the full pages code: http://moha.iarp.ca/index.txt Header: http://moha.iarp.ca/includes/header.txt session http://moha.iarp.ca/includes/session.txt Hopes something helps Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-522850 Share on other sites More sharing options...
iarp Posted April 22, 2008 Author Share Posted April 22, 2008 I'm not one for bumping posts alot, but i tried this code on different pages as tests and still the exact same problem. Is there such a thing as ghosts in a database? because i really don't see any other way this is happening... i'm pretty sure i've covered all changes i've made recently and nothing seemed to revert it back to working state. Lucky enough i have a back-up copy from a couple days ago that i can use... just i lose alot of work ~.~ Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-523656 Share on other sites More sharing options...
iarp Posted April 22, 2008 Author Share Posted April 22, 2008 As a last resort, i only had 3 user entrys, 2 were myself and 1 was a friend. So i clear and remade the whole users database. I made my account, activated it.. gave myself the permissions i need via phpMyAdmin... and the same message ~.~ this is driving me up the wall! Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-523662 Share on other sites More sharing options...
mrdamien Posted April 22, 2008 Share Posted April 22, 2008 1. Is 'DB_USER' a variable or a constant? $DB_USER vs define('DB_USER','') 2. "SELECT * FROM " . DB_USER . " WHERE `active` != NULL" I think its supposed to be "SELECT * FROM " . DB_USER . " WHERE `active` IS NOT NULL" Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-523690 Share on other sites More sharing options...
iarp Posted April 22, 2008 Author Share Posted April 22, 2008 Yes it's DEFINE('DB_USERS', 'MOHA_users'); for the table name. Theres something wrong with my php coding because i just connected to a fresh new database... added my tables .. registered, and the EXACT SAME message. Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-523695 Share on other sites More sharing options...
mrdamien Posted April 22, 2008 Share Posted April 22, 2008 Try this, and post any/all errors: $query1 = "SELECT * FROM `" . DB_USER . "` WHERE `active` IS NOT NULL;"; $result1 = mysql_query($query1) or die(mysql_error()); $user_activate = mysql_num_rows($result1); $usernames = array(); if ($user_activate >= 0) { while ($user_check = mysql_fetch_assoc($result1)){ $usernames[] = $user_check['username']; //change to what the username field is on your db } echo "<p><a href=\"view_users.php\">Accounts awaiting activation: "; foreach ($usernames as $value){ print $value.", "; } echo "</a></p>"; } Edit: There was an error in jonsjava's code. The "$usernames[] .= ..." section should not have had a period in it. Ex: "$usernames[] = ..." Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-523705 Share on other sites More sharing options...
iarp Posted April 22, 2008 Author Share Posted April 22, 2008 No errors, this is all thats shown in the source code of the page. Theres gotta be something wrong with my coding. <div id="admin_news"> <h1>Latest News</h1> <p><a href="view_users.php">Accounts awaiting activation: </a></p> </div> Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-524005 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 my code wasn't errored. that's how you add to an array the easy way. (or at least, it's the way I always do it. try this: <?php $test = array(); $test[] .= "test1"; $test[] .= "test2"; $test[] .= "test3"; $test[] .= "test4"; print_r($test); ?> Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-524009 Share on other sites More sharing options...
mrdamien Posted April 22, 2008 Share Posted April 22, 2008 Okay, so there aren't any errors given with your code, but php.net tells me that $arry[] = ... is for adding adding new elements. The period is for concatenation, but if it works then I guess there is no problem. @iarp, I'm out of ideas. If you can post your database structure, and the most current source code it might help. Your links above to the header/session.txt files don't work. Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-524056 Share on other sites More sharing options...
iarp Posted April 22, 2008 Author Share Posted April 22, 2008 header.php <?php //start output buffering ob_start(); //start a session session_name('MOHA'); session_start(); include ('session.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta name="Description" content="Unofficial Website for the MOHA" /> <meta name="Keywords" content="MOHA, Minor Oaks Hockey Association, Oakville, Hockey" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MOHA - <?php echo$page_title;?></title> <!-- ADDS AUTOMATIC PAGE TITLE TO THE TOP BAR OF BROWSERS WITH "MOHA - " FIRST --> <!-- CSS PAGE --> <link rel="stylesheet" type="text/css" href="/css/style.css" /> <!-- JAVASCRIPT SHEETS DON'T EDIT THESE --> <script type="text/javascript" src="/css/dropdowntabs.js"></script> <script type="text/javascript" src="/css/chrome.js"></script> <script type="text/javascript" src="/css/external.js"></script> </head> <body> <a name="top"></a> <div id="edit"><h1> THIS WEBSITE IS A BETA VERSION AND BEING EDITED, THE ORIGINAL IS LOCATED AT <a href="http://www.moha.on.ca">http://www.moha.on.ca</a></h1><a href="http://validator.w3.org/check?uri=referer" class="external">EDITORS LINK</a></div> <div id="container"> <!-- MAIN HEADER --> <div id="header"> <h1>MINOR OAKS HOCKEY ASSOCIATION INC</h1> <h3>1026 SPEERS ROAD, UNIT 8-9, OAKVILLE, ON L6L 2X4 905-338-9220 FAX 905-338-9677 www.moha.on.ca</h3> </div> <!-- TOP NAVIGATION BAR --> <div id="navigation"> <a href="../" title="Home">Home</a> | <a href="../code_of_conduct.php" title="MOHA's Code of Condust">Code of Conduct</a> | <a href="../moha_bylaw.php" title="MOHA Bylaw">MOHA Bylaw's</a> | <a href="../contact.php" title="Contact the MOHA">Contact Us</a> | <a href="../helpful_links.php" title="Helpful Links">Helpful Link's</a> | <?php if((isset($_SESSION['user_id'])) && (!strpos($_SERVER['PHP_SELF'], 'logout.php'))){ if ($userlevel >= "2") {echo '<a href="../admin/">Admin</a> | ';} echo '<a href="../logout.php">Logout</a>'; } else { echo '<a href="../login.php">Login</a> | '; echo '<a href="../register.php">Register</a>'; } ?> <!-- Welcome to: <font color="#591F20"><?php echo $YAH_title; ?></font><br /> --> </div> <?php include('menu.php'); ?> <!-- END TOP NAVIGATION BAR --> session.php <?php $firstname = ucwords($_SESSION['first_name']); $userlevel = $_SESSION['userlevel']; $userid = $_SESSION['user_id']; DEFINE('DB_USERS', 'MOHA_users'); DEFINE('DB_CONTENT', 'MOHA_content'); DEFINE('DB_URLS', 'MOHA_urls'); DEFINE('DB_CAT', 'MOHA_category'); DEFINE('PAGE_DISPLAY', '10'); ?> mysql_connect.php <?php #mysql_connect.php DEFINE ('DB_USER', 'username'); DEFINE ('DB_PASS', 'password'); DEFINE ('DB_HOST', 'host'); DEFINE ('DB_NAME', 'database name'); if ($dbc = mysql_connect(DB_HOST, DB_USER, DB_PASS)) { if (!mysql_select_db(DB_NAME)) { trigger_error("Could not select the database!\n<br />MySQL Error: " . mysql_error()); include ('footer.php'); exit(); } } else { trigger_error("Could not connect to MySQL!\n<br />MySQL Error: " . mysql_error()); include('footer.php'); exit(); } function escape_data($data) { if (ini_get('magic_quotes_gpc')){ $data = stripslashes($data); } if(function_exists('mysql_real_escape_string')) { global $dbc; $data = mysql_real_escape_string(trim($data), $dbc); } return $data; } ?> (Admin section) index.php <?php $page_title = 'Admin Panel'; $YAH_title = 'Admin Panel'; include ('../includes/header.php'); if ($userlevel >= "2"){ require_once('../includes/mysql_connect.php'); ?> <div id="content"> <h1>Welcome, <?php echo $firstname; ?>!</h1> <?php if ($userlevel >= "9") {echo '<p><a href="view_users.php">View Current Users</a></p>';} ?> <p><a href="add_url.php">Add a URL</a> to the <a href="../helpful_links.php">Helpful Links</a> webpage</p> <div id="admin_news"> <h1>Latest News</h1> <?php if ($userlevel >= "9") { // shows if theres a url waiting approval $query = "SELECT approved FROM " . DB_URLS . " WHERE approved = 'N'"; $result = @mysql_query($query); $link_app = mysql_num_rows ($result); if ($link_app > 0) echo "<p> <a href=\"edit_url.php\">You have $link_app link(s) waiting on approval</a></p>"; //shows if theres a user waiting approval. $query1 = "SELECT * FROM `" . DB_USERS . "` WHERE `active` IS NOT NULL;"; //i also tried COUNT(*) and i get the , from print $value.", "; string. $result1 = mysql_query($query1) or die(mysql_error()); $user_activate = mysql_num_rows($result1); $usernames = array(); if ($user_activate >= 0) { while ($user_check = mysql_fetch_assoc($result1)){ $usernames[] = $user_check['username']; //change to what the username field is on your db } echo "<p><a href=\"view_users.php\">Accounts awaiting activation: "; foreach ($usernames as $value){ print $value.", "; } echo "</a></p>"; } } ?> </div> <div align="center"> <h3>Change Your Password</h3> <form action="change_password.php" method="post" class="changepassword"> <b>New Password:</b> <input type="password" name="password1" size="20" maxlength="20" /> <b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /> <input type="submit" name="submit" value="Change My Password" /> <input type="hidden" name="submitted" value="TRUE" /> </form> </div> </div> <!-- END CONTENT --> <?php 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. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-524181 Share on other sites More sharing options...
iarp Posted April 23, 2008 Author Share Posted April 23, 2008 Forgot to add database: Table: MOHA_users: Structure: user_id username first_name last_name email password ip_address userlevel active registration_date currently in MOHA_users: 15 iarp Ian R-P [email protected] hd5-password ipaddress 10 NULL 2008-04-22 00:31:58 Table: MOHA_urls Structure: url_id url title description submitter approved currently in MOHA_urls 23 www.moha.on.ca Current MOHA Website The current MOHA website. Ian Y 20 www.omha.net/ Ontario Minor Hockey Association OMHA's Website Ian Y Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-524663 Share on other sites More sharing options...
mrdamien Posted April 23, 2008 Share Posted April 23, 2008 currently in MOHA_users: 15 iarp Ian R-P [email protected] hd5-password ipaddress 10 NULL 2008-04-22 00:31:58 I assume by "NULL" you mean its actually empty, and doesn't have the string "NULL" in it. I tested your script on my machine, and it worked as expected. Therefore the script is not erroneous, so there is probably a bad table/column/variable reference that you didn't notice. Edit: I just remembered, that if your `active` column is set to NOT NULL, then the != or IS NOT NULL comparison won't work. In this case, you would need to use `active` != "" Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-524678 Share on other sites More sharing options...
iarp Posted April 23, 2008 Author Share Posted April 23, 2008 The script i used to create the table was CREATE TABLE `MOHA_users` ( `user_id` int(10) unsigned NOT NULL auto_increment, `username` varchar(15) NOT NULL default '', `first_name` varchar(20) NOT NULL default '', `last_name` varchar(40) NOT NULL default '', `email` varchar(40) NOT NULL default '', `password` varchar(90) NOT NULL default '', `ip_address` varchar(15) NOT NULL default '0', `userlevel` tinyint(1) unsigned NOT NULL default '2', `active` varchar(32) default NULL, `registration_date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`user_id`) ) TYPE=MyISAM; So active's default is NULL, but on the registration page, it sets that column to a string of characters and then gets reset to NULL after they follow an activation link via e-mail Quote Link to comment https://forums.phpfreaks.com/topic/102095-ghost-entry-in-my-database/#findComment-524685 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.