huesped214 Posted July 22, 2008 Share Posted July 22, 2008 <?php if (!isset($_SESSION)) { session_start(); } //This is supposed to be in an include file not here, i just was doing some tests $hostname_epikcon = "myhost"; $database_epikcon = "mydb"; $username_epikcon = "myuser"; $password_epikcon = "mypass"; $epikcon = mysql_pconnect($hostname_epikcon, $username_epikcon, $password_epikcon) or trigger_error(mysql_error(),E_USER_ERROR); //end of include file function login() { $username=$_GET['username']; $password=$_GET['password']; //the problem is HERE if i echo the $database_epikcon var i get an empty var echo $database_epikcon; mysql_select_db($database_epikcon, $epikcon); $LoginRS__query=sprintf("SELECT name, password FROM users WHERE name=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $epikcon) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $_SESSION['name'] = $loginUsername; echo 'OK'; } else { echo 'errore'; } return $LoginRS; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/ Share on other sites More sharing options...
budimir Posted July 22, 2008 Share Posted July 22, 2008 You can not echo a connection to the DB! The error message you can put $epikcon = mysql_pconnect($hostname_epikcon, $username_epikcon, $password_epikcon) or die (mysql_error()); So, if the program doesn't stop here, your connection is successfull. Quote Link to comment https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/#findComment-596273 Share on other sites More sharing options...
huesped214 Posted July 22, 2008 Author Share Posted July 22, 2008 im just echoing a variable that holds my database name, just a simple string and it is empty as well the other 3 vars: that hold the DB password, DB host and DB name Quote Link to comment https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/#findComment-596277 Share on other sites More sharing options...
mmarif4u Posted July 22, 2008 Share Posted July 22, 2008 Did you try to echo it outside the function. Quote Link to comment https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/#findComment-596279 Share on other sites More sharing options...
DoddsAntS Posted July 22, 2008 Share Posted July 22, 2008 the variables aren't accessible inside your login function. I would suggest moving the mysql_select_db outside of the function and passing the connection var as a function argument Quote Link to comment https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/#findComment-596280 Share on other sites More sharing options...
huesped214 Posted July 22, 2008 Author Share Posted July 22, 2008 yes, it works only outside the function... the connection is ok but when i enter the function the vars are empty, im kinda new to php but i thought the vars outside the function were publics/globals mysql_select_db($database_epikcon, $epikcon); at this line i got this: mysql_select_db(); -----> error but if i try outside the function it works... maybe the only way is to pass them as params? Quote Link to comment https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/#findComment-596284 Share on other sites More sharing options...
huesped214 Posted July 22, 2008 Author Share Posted July 22, 2008 thanks DoddsAntS solved Quote Link to comment https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/#findComment-596285 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.