Thread: MySQL

Results 1 to 5 of 5
  1. #1 MySQL 
    Registered Member
    Join Date
    Mar 2016
    Posts
    94
    Thanks given
    2
    Thanks received
    4
    Rep Power
    11
    I'm pretty new to working with MySQL, so anyway I downloaded a login/register system which I am working on for learning purposes.

    Anyway I've been told that the MySql is old and was wondering if anyone could give me a hand and tell me more about this, I believe it is to do with the word WHERE being used in the query and it is outdated or something?


    Code:
    <?php
    	ob_start();
    	session_start();
    	require_once 'dbconnect.php';
    	
    	// if session is not set this will redirect to login page
    	if( !isset($_SESSION['user']) ) {
    		header("Location: index.php");
    		exit;
    	}
    	// select loggedin users detail
    	$res=mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
    	$userRow=mysql_fetch_array($res);
    ?>
    Also I plan to work on a members page showing all the members registered if anyone has any tips for this I would appreciate it.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Dec 2016
    Posts
    21
    Thanks given
    1
    Thanks received
    2
    Rep Power
    11
    From what I understand, you mean you're getting a warning that says "The mysql extension is deprecated" ?

    This means that, in the future mysql_connect() will be removed. Use mysqli_connect or PDO instead

    Just google for MySQLI and how to use it in PHP.

    There is nothing wrong with the query, it's valid.
    Reply With Quote  
     

  3. Thankful user:

    Community VeteranSub

  4. #3  
    aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa
    Planets's Avatar
    Join Date
    Aug 2014
    Age
    29
    Posts
    2,159
    Thanks given
    673
    Thanks received
    1,955
    Rep Power
    5000
    use pdo

    Reply With Quote  
     

  5. Thankful users:


  6. #4  
    Community Veteran

    Songoty's Avatar
    Join Date
    Dec 2007
    Posts
    2,740
    Thanks given
    211
    Thanks received
    1,034
    Rep Power
    2455
    As others have said it's best to move towards using the mysqli extension, or prepared statements. Your query is fine.

    A total member page would be pretty easy. You would probably want to use a page system to display all the members since having potentially thousands on one page isn't going to be the best looking or best for performance.

    Here's a simple example of how to do that, this isn't proper PHP what so ever and won't work if you throw it into a PHP script, but it should help you understand a simple way to do pages

    Code:
    <?php
    	if(isset($_GET['page'])) {
    		$page = sanitize($_GET['page']);
    	} else {
    		$page = 1;
    	}
    	$limit_upper = $page * 25;
    	$query = your_query("SELECT * FROM members ORDER BY id/date_registered DESC LIMIT 25 OFFSET $limit_upper"); //LIMIT can also be used as (LIMIT [YOUR_OFFSET] [ROWS_TO_DISPLAY]) instead of (LIMIT [ROWS_TO_DISPLAY] OFFSET [YOUR_OFFSET])
    	foreach($query as $row) {
    		echo $row['whatever'];
    	}
    ?>
    Things of note:

    1. Always sanitize any information received directly from the user. Always. Even if you're not going to throw it into a query, make a habit of it. Trusting anything the user gives you will lead to problems eventually.
    2. The query provided may not be valid but is the general layout of a query. Essentially you want to order it by the users id or date of registration.
    Reply With Quote  
     

  7. #5  
    Registered Member
    Join Date
    Mar 2016
    Posts
    94
    Thanks given
    2
    Thanks received
    4
    Rep Power
    11
    Thanks everyone for the feedback, Looking into it now.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. Replies: 17
    Last Post: 07-05-2008, 09:49 AM
  2. Replies: 86
    Last Post: 02-29-2008, 05:31 PM
  3. Replies: 2
    Last Post: 12-02-2007, 03:57 AM
  4. Full Dodian Download NON MYSQL Editable
    By Im So Leet in forum Downloads
    Replies: 10
    Last Post: 10-24-2007, 06:46 PM
  5. Integration of MySQL into your PServer
    By Guthan in forum Tutorials
    Replies: 10
    Last Post: 06-12-2007, 06:50 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •