Jump to content

Connect to db from within a class


M.O.S. Studios

Recommended Posts

I'm trying to do a db query from within a class, but i keep getting an error saying that my db doesn't exist.

 

I tried making the db connection from within the class

 

I also tried making the connection before i called the class

 

both held the same result.

 

is there something that I'm missing?

 

 

 

thanks in advance

Link to comment
Share on other sites

<?php
CLASS member{

function login($username, $password){

	$q = mysql_query("SELECT * FROM `users` WHERE username = '".$username."' AND password = '".$password."'") or die (mysql_error());
	$r = mysql_num_rows($q);

	if ($r == 1){
		$_SESSION['logged'] = 1;
		RETURN TRUE;
	}else{
		RETURN FALSE;
	}
}
}
?>

 

 

$members = new member();
if($_POST['member_action']=='login'){
 include('link.php'); //link to a file that has the mysql_connect function in it
 $members->login($_POST['member_name'], $_POST['member_pass']);
 mysql_close($link);
}

<form action="*current url*" method="POST">
<div class='login'>
<div class='username'>
	Username:
</div>
<div class='username_input'>
	<input type="text" name="member_name">
</div>
<div class='password'>
	Password:
</div>
<div class='password_input'>
	<input type="password" name="member_pass">
</div>	
</div>

<div class='login_options'>
<div class='submit'><input type='submit' name='member_action' value='login'></div>
</div>
</form>

 

when ever i run the mysql_query i get this e_warning:

 

Table '*table name*' doesn't exist

 

weird???

any ideas

Link to comment
Share on other sites

Table '*table name*' doesn't exist

 

That back-ticks around the table name in the query are not a problem.

 

The error is self explanatory, the table name you are using in the query doesn't exit in the database that you have selected.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.