Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

id_utilizador sempre 1 !?

$
0
0
Boas malta. O problema é o seguinte: sempre que clico no ID para ir para a página de atualização de utilizadores ele lê sempre o ID=1 ou seja qualquer que seja o id em que clique ele vai sempre abrir o id=1 mesmo que o link aponte por exemplo para o id=4 como a imagem mostra:

Imagem Colocada

Aqui está a imagem da lista de utilizadores:

Imagem Colocada

lista_utilizadores.php:

Código :
<?php require_once('Connections/dbconfig.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_dbconfig, $dbconfig);
$query_Users = "SELECT * FROM tbl_utilizadores";
$Users = mysql_query($query_Users, $dbconfig) or die(mysql_error());
$row_Users = mysql_fetch_assoc($Users);
$totalRows_Users = mysql_num_rows($Users);

mysql_connect('localhost', 'root', 'mysql');
mysql_select_db('dbrelpro');
$sql="SELECT * FROM tbl_utilizadores";
$Users=mysql_query($sql);
$row_Users = mysql_fetch_assoc($Users);
?>
<!doctype html>
<html>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-2" />
<head>
<title>Lista de Utilizadores</title>
</head>

<body>
<table width="200" border="1">
<tr>
<th scope="col">ID</th>
<th scope="col">Nome</th>
<th scope="col">Apelido</th>
<th scope="col">Email</th>
<th scope="col">Utilizador</th>
<th scope="col">Password</th>
<th scope="col">Administrador</th>
<th scope="col">Apagar</th>
</tr>
<?php do { ?>
<tr>
<td><a href="update.php?id_utilizador=<?php echo $row_Users['id_utilizador']; ?>"><?php echo $row_Users['id_utilizador']; ?></a></td>
<td><?php echo $row_Users['p_nome']; ?></td>
<td><?php echo $row_Users['u_nome']; ?></td>
<td><?php echo $row_Users['email']; ?></td>
<td><?php echo $row_Users['utilizador']; ?></td>
<td><?php echo $row_Users['password']; ?></td>
<td><?php echo $row_Users['admin']; ?></td>
<td><a href="apagar_utilizador.php?id_utilizador=<?php echo $row_Users['id_utilizador']; ?>">Apagar</a></td>
</tr>
<?php } while ($row_Users = mysql_fetch_assoc($Users)); ?>
</table>
<p>(Para actualizar registo ou apagar clicar no ID do registo pretendido)<br/>
<br/><a href="admin.php">Voltar</a>
</html>
<?php
mysql_free_result($Users);
?>
 

update.php

Código :
<?php require_once('Connections/dbconfig.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE tbl_utilizadores SET utilizador=%s, password=%s, email=%s, admin=%s, p_nome=%s, u_nome=%s WHERE id_utilizador=%s",
GetSQLValueString($_POST['utilizador'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['administrator'], "int"),
GetSQLValueString($_POST['p_nome'], "text"),
GetSQLValueString($_POST['u_nome'], "text"),
GetSQLValueString($_POST['id_utilizador'], "int"));

mysql_select_db($database_dbconfig, $dbconfig);
$Result1 = mysql_query($updateSQL, $dbconfig) or die(mysql_error());

$updateGoTo = "view_users.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_dbconfig, $dbconfig);
$query_Users = "SELECT * FROM tbl_utilizadores";
$Users = mysql_query($query_Users, $dbconfig) or die(mysql_error());
$row_Users = mysql_fetch_assoc($Users);
$totalRows_Users = mysql_num_rows($Users);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Id_utilizador:</td>
<td><?php echo $row_Users['id_utilizador']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Utilizador:</td>
<td><input type="text" name="utilizador" value="<?php echo htmlentities($row_Users['utilizador']); ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Password:</td>
<td><input type="text" name="password" value="<?php echo htmlentities($row_Users['password']); ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="email" value="<?php echo htmlentities($row_Users['email']); ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Administrator:</td>
<td><input type="text" name="administrator" value="<?php echo htmlentities($row_Users['admin'], ENT_COMPAT, 'utf-8'); ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">P_nome:</td>
<td><input type="text" name="p_nome" value="<?php echo htmlentities($row_Users['p_nome']); ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">U_nome:</td>
<td><input type="text" name="u_nome" value="<?php echo htmlentities($row_Users['u_nome']); ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Update record"><input name="Submit" type="submit" onclick="view_users.php'" value="Cancelar" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="id_utilizador" value="<?php echo $row_Users['id_utilizador']; ?>">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Users);
?>

Viewing all articles
Browse latest Browse all 14700

Trending Articles