Tengo una lista de usuarios aqui les dejo la tabla en donde los registro:
Código PHP:
-- Estructura de tabla para la tabla `comercio`
--
CREATE TABLE `comercio` (
`id_comercio` int(50) NOT NULL auto_increment,
`razon_social` varchar(100) NOT NULL,
`responsable` varchar(100) NOT NULL,
`direccion` varchar(100) NOT NULL,
`cuit` varchar(100) NOT NULL,
`telefono` varchar(100) NOT NULL,
`celular` varchar(100) NOT NULL,
`ciudad` varchar(100) NOT NULL,
`mail` varchar(100) NOT NULL,
`cod_postal` varchar(100) NOT NULL,
`observaciones` varchar(100) NOT NULL,
`usuario` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`estado` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id_comercio`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
Este es mi login.php:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p> </p>
<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="112"><b>Login</b></td>
<td width="188"><input name="login" type="text" class="textfield" id="login" /></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input name="password" type="password" class="textfield" id="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Login" /></td>
</tr>
</table>
</form>
</body>
</html>
Código PHP:
<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
/*$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
} */
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$login = clean($_POST['login']);
$password = clean($_POST['password']);
//Input Validations
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
if ($login == 'admin'& $password == 'adminsaf' ) {
session_regenerate_id();
//$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = "admin";
$_SESSION['SESS_FIRST_NAME'] = "adminsaf";
//$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: /demo/index.php");
exit();
}
//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: login-form.php");
exit();
}
//Create query
//$qry="SELECT * FROM comercio WHERE usuario='$login' AND password='".md5($_POST['password'])."'";
$qry="SELECT * FROM comercio WHERE usuario='$login' AND password='$password'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id_comercio'];
$_SESSION['SESS_FIRST_NAME'] = $member['razon_social'];
//$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: member-index.php");
exit();
}else {
//Login failed
header("location: login-failed.php");
exit();
}
}else {
die("Query failed");
}
?>
Lo que no se como hacer es para poder desde un panel de administracion que yo pueda colocar un usuario como activo y como no y dependiendo de la opcion se pueda o no loguear.
Aqui el php para realizar esa opcion:
Código PHP:
<form id="form1" name="form1" method="post" action="">
<p>
<?PHP
require_once('config.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
$db = mysql_select_db(DB_DATABASE);
$result= mysql_query("select * from comercio") or die('Error: '.mysql_error());
?>
<span class="style6">Listado de Comercios Registrados en el Sistema </span></p>
<p class="style2"> </p>
<table width="897" border="0" align="center" cellpadding="2" cellspacing="0">
<tr bgcolor="#CCCCCC">
<td class="style2"><div align="center" class="style14"><span class="style15 style3 style4 ">RAZON SOCIAL </span></div></td>
<td class="style2"><div align="center" class="style14"><span class="style15 style4 style3">RESPONSABLE</span></div></td>
<td class="style2"><div align="center" class="style14"><span class="style15 style3 style4 ">DIRECCION</span></div></td>
<td class="style2"><div align="center" class="style14"><span class="style15 style3 style4 ">CUIT</span></div></td>
<td class="style2"><div align="center" class="style14"><span class="style15 style3 style4 ">CIUDAD</span></div></td>
<td class="style2"><div align="center" class="style14"><span class="style15 style3 style4 ">TELEFONO</span></div></td>
<td class="style2"><div align="center" class="style14"><span class="style15 style3 style4 ">ESTADO</span></div></td>
<td class="style2"><div align="center"></div></td>
<td class="style2"><div align="center"></div></td>
</tr>
<?php
while ($row = mysql_fetch_array($result)){
echo"<tr>";
echo"<td><div align='center'><span class='style2'>" .$row['razon_social']. "</span></div></td>" ;
echo"<td><div align='center'><span class='style2'>" .$row['responsable']. "</span></div></td>" ;
echo"<td><div align='center'><span class='style2'>" .$row['direccion']. "</td>" ;
echo"<td><div align='center'><span class='style2'>" .$row['cuit']. "</span></div></td>" ;
echo"<td><div align='center'><span class='style2'>" .$row['ciudad']. "</span></div></td>" ;
echo"<td><div align='center'><span class='style2'>" .$row['telefono']. "</span></div></td>" ;
echo"<td><div align='center'><span class='style2'>" .$row['ESTADO']. "</span></div></td>" ;
echo"<td ><div align='center'><span class='style2'><a href='activo_comercio.php?id=" .$row['id_comercio']. "'>ACT</a></span></div></td>";
echo"<td ><div align='center'><span class='style2'><a href='desactivo_comercio.php?id=" .$row['id_comercio']. "'>DES</a></span></div></td>";
echo" </tr>";
}
?>
</table>
<p class="style5 style2"> </p>
</form>
Desde ya muchas gracias por adelantado