Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6204011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:00:57+00:00 2026-05-24T05:00:57+00:00

Thanks. I would like to let user login , And i try to do

  • 0

Thanks. I would like to let user login , And i try to do it in oop way

Here is the loginPage.php

<html>
<body>
<?php require_once("connection.php");
$instance=new connection("527442_1","chi1234a","foodil_zxq_1");
if (isset($_POST['s'])) {
    $SecIns=new login($_POST['u'],$_POST['p']);
    echo $SecIns->enter();
}
?>
<form name="fm" method="POST" action="show.php">
User Name :<input type="text" name="u">
<br>
Password: <input type="password" name="p">
<br>
<input type="submit" name="s">
</form>
</body>
</html>

Here is the oop code which i fail Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource

<?php

class connection
{var $user;
var $pass;
var $db;

function __construct($user,$pass,$db){
$this->user=$user;
$this->pass=$pass;
$this->db=$db;
}

function conn(){
$conn=mysql_connect('localhost' , $this->user , $this->pass) or die ("Can't connect server");
mysql_select_db($this->db,$conn) or die ("DB error");
}
}

class login extends connection
{

function __construct($id,$pwd)
{$this->id=$id;
$this->pwd=$pwd;
}

function enter()
{$this->query="SELECT * FROM test WHERE id='".$this->id."' AND pwd='". $this->pwd."';";
$result=mysql_query($this->query,$this->conn) or die ("Error:" . mysql_error());
if (mysql_num_rows($this->result)<1)
return "Not correct user";
else
return "Login success";
}
}
?>

The problem is at the function enter() .Should be the format problem?? But i spend a long time on it . Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:00:59+00:00Added an answer on May 24, 2026 at 5:00 am

    While it’s commendable that you want to add organization to your code, adding the methods into a class doesn’t automatically make it OOP. I recommend you read up on the basics and then reorganize your classes.

    As for your problem,

    $result=mysql_query('$this->query','$this->conn') or die( ..
    --------------------------^
    

    Those variables you passed are treated as literal strings because you’ve quoted them. you need to pass it an actual query and a connection object. Just remove the quotes.

    Also, I recommend you look into parametrized queries : http://php.net/manual/en/book.pdo.php

    EDIT

    Looking at your code further, these tips might improve your code

    • Use upper case names for your classes. This makes them easier to read.
    • You’re correct in moving your connection to a different class, but your usage is wrong.
    • Even though you’ve extended your Login class from your Connection class, you don’t instantiate a connection object for use inside your Login class even though you refer to it in your code (e.g. – $this->conn)
    • Instantiate your connection and pass it as a parameter for your other classes. Don’t extend them from the connection.

      $conn = new Connection($username, $pass, $host, $db);
      $login = new Login($conn);
      $login->doLogin($username, $password);

    And have a query() method in your connection, so you can call that method from your other classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a simple pojo which is filled thanks to hibernate. I would like
I am looking to query my database based on what the user would like
I would like to know about how to delete a folder once user select
Let's say I have a user class setup with validation like this: [MetadataType(typeof(ssUserMetaData))] public
I would like to move all Javascript from HTML markup into separate files but
I would like to let users customize pages, let's call them A and B.
I am using a UIPanGestureRecognizer on several card-like views to let the user move
here was my situation. I was using paperclip to let user upload images. It
Right first of I would like to thank everyone for helping me out on
Once again my silliness has struck. I would like to thank everyone who helped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.