Jump to content

Argg errors :_ mysql_num_rows invalid and resused function?


jrws

Recommended Posts

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

  Quote
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:
  Quote
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!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{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.

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

  Quote

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

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

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>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.