Stuck with PHP

Discussion in 'Software' started by Wookie, Nov 18, 2004.

  1. Wookie

    Wookie Sergeant Major

    OK I am trying to write really nice code with a single file for all my global functions

    My first file login.php looks like this

    Code:
    <?php
    require("global_functions.php");
    $login = $_POST['login'];
    $pass = $_POST['pass'];
    $login = @substr($login, 0, 15);
    $login = @strip_tags($login); 
    $login = @stripslashes($login);
    $enc = sha1($pass) + md5($pass);
    	
    	$query = "SELECT *  FROM 'eop_users' WHERE login='$login' AND password='$enc' LIMIT 1;";
    	$result = myconn($query);
    	echo "$result";
    	$num = mysql_numrows($result);
    	$i=0;
    	
    	if ($num==0) {
    		//Login is not found
    	} else { //ligon is found
    		while ($i < $num) {
    		$nm = mysql_result($result,$i,"username");
    		$ps = mysql_result($result,$i,"password");
    		$i++;
    		}//end while
    	}//end else
    
    if ($login == $nm &&  $enc == $ps) { 
    //This is gonna be changed for session cookies
    //I am not keeping this code
    	setcookie("val", "yes", time()+3600);
    	setcookie("usernm", $nm, time()+3600);
    	setcookie("pass", $ps, time()+3600);
    	header('location:index');
    }
    else
    {
    echo 'Incorrect Login, <a href="index.php">Try Again?</a>';
    }
    ?>
    
    It includes a file called global_functions.php that looks like this

    Code:
    <?PHP
    //Variable Initilize
    $code = "new";
    function myconn($sql){
    	$DBhost = "localhost";
    	$DBuser = "username";
    	$DBpass = "password";
    	$DBName = "databasename";
    	mysql_connect($DBhost,$DBuser,$DBpass) or die('Unable to connect to database');
    	@mysql_select_db("$DBName") or die('Unable to select database $DBName');
    	$result1=mysql_query($sql);
    	return $result1;
    	mysql_close();
    } //end myconn function
    
    I Keep getting this error
    Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in login.php on line 13

    I am pulling my hair out why I cant get this to work, ive used the myconn function with other SQL statements passed and it worked fine. If anyone catches anything i missed let me know. Thanks.
     
  2. Wookie

    Wookie Sergeant Major

    I got it
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds