Jump to content

phpmysql login srcript


joeizang

Recommended Posts

Hi folks,

I am loving php but help me solve this problem. Every time I try to login and test I always get an error that there is something wrong with the mysql_connect line it returns a fatal error.

<?php
  class dbconect{
      public $host;
      public $user;
      public $passwd;
      public $db;
     
      public function __construct(){
            $this->host = "localhost";
            $this->user = "sa";
            $this->passwd = "123abc456";
            $this->db = "prodigee";
           
            $conn = mysql_connect($this->host, $this->user, $this->passwd); //(this is the line it complains about)
            mysql_select_db($this->db);
      }
      function selquery(){
           
            $uname = $_POST['username'];
            $pwd = $_POST['password'];
     
            $result = mysql_query("SELECT * FROM staff WHERE username = '$uname' AND password = SHA1('$pwd')");
            if(!$result){
                  echo "There was an error while validating your credentials! Please try again";
                  echo "<a href=".$_SERVER['PHP_SELF'].">Login Again</a> ";
                  exit;
            }else{
                  session_start();
                 
            }
           
           

      }
  }
 
 
      /**This class will handle all database related tasks. This file will then be reqired
      in the main pages that will be interfaced by the user.
  **/
 
?>


this is how I connect to it from the form

//call database connection class so database can be checked.
      $conn = new dbconect;
      $conn->selquery($_POST['username'], $_POST['password']);
      }

pls let me know.
Link to comment
https://forums.phpfreaks.com/topic/34157-phpmysql-login-srcript/
Share on other sites

for the database connection, try this:

<?php
$link = mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error());
$db_selected = mysql_select_db('database', $link) or die ('Error while connecting to database: ' . mysql_error());
?>

Try this first, this works for my site.

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.