How can i make a proper database login directly from the user created on Cpanel?

php android mysql

28 просмотра

1 ответ

0 Репутация автора

i'm building an android application and i'm using phps scripts to do all my requests, i'm kind of new with this so i hope you all can help me. Normally if you are going to connect to a db using php you do the connection.php file and the login.php using the connection.php.

For Security purposes i´m not using a UsersTable in my DB, i'm connecting directly with the user you create on your Cpanel to manage the DB, so my php connection its something like this.

$user = $_POST["Us"];
$pass= $_POST["Pss"];
$connection = mysqli_connect($server,$user, $pass, $db);
if (!$connection) 
{die ("Error de conexion a la base de datos ... \n" . mysql_error ());}
else {echo 'Ok';}     

but i need to make a request if the connection.php answer is OK then on my DataOb.php and other files do this for example to obtain some data?

$username = $_GET["Us"];
$statement=mysqli_prepare($connection,"SELECT idTrabajador,`Nombre del Trabajador` FROM `tablausuario` WHERE `Usuario`=?");
$response = array();
$response["success"] = false;
$response["success"] = true;
$response["idTrabajador"] = $idTrabajador;
$response["Nombre del Trabajador"] = $name;
echo json_encode($response);

the thing is , how can i create the "if" condition, obtain the user? and keep the connection open to do the requests on the other files?, its better to use session_start(), so i can close the connection after? or i'm i3n the right path?

Автор: user8793330 Источник Размещён: 08.11.2017 11:25

Ответы (1)

0 плюса

1443 Репутация автора

Instead of echoing "ok" why don't you set a variable.

 $connected = true;

And then elsewhere in the code just check the variable:

if($connected) {
    //execute your code here
Автор: dave Размещён: 08.11.2017 11:45
Вопросы из категории :