M.O.S. Studios Posted July 11, 2010 Share Posted July 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/207425-connect-to-db-from-within-a-class/ Share on other sites More sharing options...
atrum Posted July 11, 2010 Share Posted July 11, 2010 Let's see your code. Quote Link to comment https://forums.phpfreaks.com/topic/207425-connect-to-db-from-within-a-class/#findComment-1084432 Share on other sites More sharing options...
M.O.S. Studios Posted July 11, 2010 Author Share Posted July 11, 2010 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/207425-connect-to-db-from-within-a-class/#findComment-1084478 Share on other sites More sharing options...
atrum Posted July 11, 2010 Share Posted July 11, 2010 hmmm, well the only thing that sticks out for me is that normally I don't put quotes around the table. So try changing. SELECT * FROM `users` <- to -> SELECT * FROM users Quote Link to comment https://forums.phpfreaks.com/topic/207425-connect-to-db-from-within-a-class/#findComment-1084519 Share on other sites More sharing options...
PFMaBiSmAd Posted July 11, 2010 Share Posted July 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/207425-connect-to-db-from-within-a-class/#findComment-1084527 Share on other sites More sharing options...
.josh Posted July 11, 2010 Share Posted July 11, 2010 make sure the table name is spelled right (case-sensitive), also your script could have failed to select a db in the first place... Quote Link to comment https://forums.phpfreaks.com/topic/207425-connect-to-db-from-within-a-class/#findComment-1084551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.