joeizang Posted January 14, 2007 Share Posted January 14, 2007 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 More sharing options...
burkezillar Posted January 14, 2007 Share Posted January 14, 2007 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. Link to comment https://forums.phpfreaks.com/topic/34157-phpmysql-login-srcript/#findComment-160666 Share on other sites More sharing options...
matto Posted January 14, 2007 Share Posted January 14, 2007 Change the offending line to this[code]$conn = mysql_connect($this->host, $this->user, $this->passwd) or die("<tt>" . mysql_error() . "</tt>");[/code]Post back your findings.... :) Link to comment https://forums.phpfreaks.com/topic/34157-phpmysql-login-srcript/#findComment-160670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.