www.webdeveloper.com
Results 1 to 3 of 3

Thread: member log in script works in localhost but reads "Resource id #4" on the live site

Threaded View

  1. #1
    Join Date
    Jul 2012
    Posts
    14

    member log in script works in localhost but reads "Resource id #4" on the live site

    I used this great log in PHP tutorial script from sourcecodester.com
    http://www.sourcecodester.com/tutori...-phpmysql.html

    It works perfectly on my local host but when I moved to the live server it just echoes "Resource id #4" instead of logging in and directing to menu.php

    PHP Code:
    <?php

         
    //Start session
         
    session_start();

         require_once
    'db_connect.php';

         
    //db connection details
         
    $mysql_hostname $db_host;
         
    $mysql_user     $db_username;
         
    $mysql_password $db_pass;
         
    $mysql_database $db_name;
         
    $prefix "";
         
    $bd mysql_connect($mysql_hostname$mysql_user$mysql_password) or die("Could not connect to the database");
         
    mysql_select_db($mysql_database$bd) or die("Could not select the database");
     
         
    //Array to store validation errors
         
    $errmsg_arr = array();
     
         
    //Validation error flag
         
    $errflag false;
     
         
    //Function to sanitize values received from the form. Prevents SQL injection
         
    function clean($str) {
              
    $str = @trim($str);
              if(
    get_magic_quotes_gpc()) {
                   
    $str stripslashes($str);
              }
              return 
    mysql_real_escape_string($str);
         }
     
         
    //Sanitize the POST values
         
    $signin_email clean($_POST['signin_email']);
         
    $signin_pass clean($_POST['signin_pass']);
     
         
    //Input Validations
         
    if($signin_email == '') {
              
    $errmsg_arr[] = 'Username missing';
              
    $errflag true;
         }
         if(
    $signin_pass == '') {
              
    $errmsg_arr[] = 'Password missing';
              
    $errflag true;
         }
     
         
    //If there are input validations, redirect back to the login form
         
    if($errflag) {
              
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
              
    session_write_close();
              
    header("location: index.php");
              exit();
         }
     
         
    //Create query
         
    $qry="SELECT * FROM members_tbl WHERE email='$signin_email' AND pass='$signin_pass'";
         
    $result=mysql_query($qry);
      
         echo 
    $result;
     
         
    //Check whether the query was successful or not
         
    if($result) {
              if(
    mysql_num_rows($result) > 0) {
                   
    //Login Successful
                   
    session_regenerate_id();
                   
    $member mysql_fetch_assoc($result);
                   
    $_SESSION['SESS_MEMBER_ID'] = $member['user_id'];
                   
    $_SESSION['SESS_FIRST_NAME'] = $member['username'];
                   
    session_write_close();
                   
    header("location: menu.php");
                   exit();
              }else {
                   
    //Login failed
                   
    $errmsg_arr[] = 'user name and password not found';
                   
    $errflag true;
                   if(
    $errflag) {
                        
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
                        
    session_write_close();
                        
    header("location: index.php");
                        exit();
                   }
              }
         }else {
              die(
    "Query failed");
         }
    ?>
    ?>
    I have googled the issue and found the comment below but I'm not sure how I can relate it to my code.

    "You are trying to print a mysql resource variable instead of the values contained within the resource it references. You must first try to extract the values you have gotten by using a function such as mysql_fetch_assoc()."

    Any help would be much appreciated. Thanks.
    Last edited by conor909; 01-11-2014 at 07:38 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles