jrws Posted February 13, 2009 Share Posted February 13, 2009 Alright here's the problemo, so I am trying to make a register page, and it keeps giving the error database is not selected, so if I remove or die from the query it says Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\News_System\register.php on line 20 So I see if my function file works (it does) but then when I test to see if there are any errors from the functions I get this error:Fatal error: Cannot redeclare encrypt() (previously declared in D:\xampp\htdocs\News_System\lib\phpdesigner_tmp19.php:5) in D:\xampp\htdocs\News_System\lib\functions.php on line 14 So here is the functions page: <?php session_start(); require_once ('config.php'); //Functions function encrypt($x, $salt = null) { //Simply encrypts a string using md5 and sha1 if ($salt == null) { $x = md5(sha1($x)); return $x; } else { $x = md5(sha1($x . $salt)); return $x; } } function clean($string) { if (get_magic_quotes_gpc()) { $string = stripslashes($string); } elseif (!get_magic_quotes_gpc()) { $string = addslashes(trim($string)); } $string = trim($string); $string = escapeshellcmd($string); $string = mysql_real_escape_string($string); $string = stripslashes(strip_tags(htmlspecialchars($string))); return $string; } function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function usernameExists($user){ $mysql_query = "SELECT * FROM user WHERE username = '$user'"; $mysql_result = mysql_query($mysql_query)or die('Error: '.mysql_error()); if(mysql_num_rows($mysql_result)>0){ return true; }else{ return false; } } function activationEmail($email,$code){ $to = $email; $sub = 'Activation at NewsSystem'; $mes = 'Hello there, welcome to News-System!<br>'; $mes .= 'So the first step is to activate your account, so that you may login.'; $mes .='\n Go to this adress:\n'; $mes .='<a href="'.$siteURL.'/register?activate='.$code.'"'; $send = mail($to,$sub,$mes,$headers); if(!$send){ return false; }else{ return true; } } ?> Can't figure out what its problem is, this should all be working, but it isn't so any help with this is appreciated, also if you need more code (such as the config) please ask as I did not know what to include. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 13, 2009 Share Posted February 13, 2009 There already is encrypt function in PHP. You can not define another one with same name. That's the reason of at least one of those warnings. Quote Link to comment Share on other sites More sharing options...
jrws Posted February 13, 2009 Author Share Posted February 13, 2009 Ok then thanks for that one, I thought there wasn't because it has never spat that error before when I used the same name... Edit: I just changed the name to safePassword and I get the same error Fatal error: Cannot redeclare safepassword() (previously declared in D:\xampp\htdocs\News_System\lib\phpdesigner_tmp21.php:5) in D:\xampp\htdocs\News_System\lib\functions.php on line 14 Quote Link to comment Share on other sites More sharing options...
waterssaz Posted February 13, 2009 Share Posted February 13, 2009 Can you show us the other page being mentioned in the error e.g D:\xampp\htdocs\News_System\lib\phpdesigner_tmp21.php This may help us to solve the problem :-) Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 13, 2009 Share Posted February 13, 2009 My mistake. There is no encrypt{} function in PHP. There's crypt, so you can use encrypt() as a function name. The reason you get this error is probably because you have encrypt() declared somewhere else (config.php perhaps?) [edit] The error message even tells you where you have it phpdesigner_tmp19.php Quote Link to comment Share on other sites More sharing options...
jrws Posted February 13, 2009 Author Share Posted February 13, 2009 Thats the exact same page, I am using PHP designer and it automatically makes a temp file for testing on localhost, it hasn't ever interfered before... edit: Found the problem, for some reason the file hadn't saved when I changed some info so what was happening was config was calling functions, and functions was calling config, personally I didn't think that would of been the problem since I said require_once but I guess it must of been. Thanks for your help. However I think I still get the mysql_error, heres the code, and I have only comented out or die() because I wanted to see what was killing it. <?php //Register page Will have ajax eventually require_once ('lib/functions.php'); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Register</title> <link rel="stylesheet" type="text/css" href="lib/default.css"> </head> <body><div class="holder"><? if ($_SESSION['username'] != '') { echo 'You are already logged in!'; } else{ echo safePassword('Test'); if (isset($_GET['activate'])) { $code = clean($_GET['activate']); $query = "SELECT code FROM user WHERE code = '$code'"; $resultA= mysql_query($query);//or die(mysql_error()); if (mysql_num_rows($resultA)>0) { $query = "UPDATE user SET u_level = 1, code ='' WHERE code = '$code' "; $resultQuery = mysql_query($query);// or die(mysql_error()); if ($resultQuery) { echo 'Successfully activated, <a href="' . $siteURL . '/login.php">login</a>'; } else{ echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>'; } } else{ echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>'; } ?> <? } } ?></div> </body></html> Quote Link to comment Share on other sites More sharing options...
samshel Posted February 13, 2009 Share Posted February 13, 2009 what does this return when uncommented? $resultA= mysql_query($query) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
jrws Posted February 13, 2009 Author Share Posted February 13, 2009 Database could not be found (And yet if I test the config file everything is A ok in there...) Quote Link to comment Share on other sites More sharing options...
samshel Posted February 13, 2009 Share Posted February 13, 2009 please post config.php code (with credentials masked of course ). there is some problem with database connection. Quote Link to comment Share on other sites More sharing options...
jrws Posted February 13, 2009 Author Share Posted February 13, 2009 <?php $host = '*****'; $db = '*****'; $user = '*****'; $pass = '*****'; $siteURL = '*****/news_system/'; $connect = mysql_connect($host,$user,$pass)or die(mysql_error()); $db = mysql_select_db($db)or die(mysql_error()); $send_email = 0; ?> Quote Link to comment Share on other sites More sharing options...
samshel Posted February 13, 2009 Share Posted February 13, 2009 is it dying at the statement mysql_select_db($db)or die(mysql_error()); or later during query? if it works at this statement and dies during our later query, that means you are switching databases some where in yoru code. Quote Link to comment Share on other sites More sharing options...
jrws Posted February 14, 2009 Author Share Posted February 14, 2009 It isn't dying anywhere in the config, so I can't figure it out... I will have to look at my code again, but at the moment I am just a tad busy XD School sometimes takes out the fun of coding. Quote Link to comment 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.