Jump to content

Help with mysql connection


huesped214

Recommended Posts

<?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;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/115975-help-with-mysql-connection/
Share on other sites

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.

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?

 

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.