Jump to content

Alterar e Eliminar como Admin


luisfffigueiredo

Recommended Posts

Bom dia,

Tenho uma página de administrador e pretendo eliminar ou alterar inscrições, o problema é que o eliminar não sei fazer sequer e o alterar só dá para alterar o 1º registo, se me pudessem ajudar agradecia.

O alterar está assim:

<?php require_once('Connections/luis.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
 $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 inscricao SET Idade=%s, BI=%s, Localidade=%s, Email=%s, Contato=%s, Nick=%s, Equipa=%s WHERE Nome=%s",
				   GetSQLValueString($_POST['Idade'], "int"),
				   GetSQLValueString($_POST['BI'], "int"),
				   GetSQLValueString($_POST['Localidade'], "text"),
				   GetSQLValueString($_POST['Email'], "text"),
				   GetSQLValueString($_POST['Contato'], "int"),
				   GetSQLValueString($_POST['Nick'], "text"),
				   GetSQLValueString($_POST['Equipa'], "text"),
				   GetSQLValueString($_POST['Nome'], "text"));

 mysql_select_db($database_luis, $luis);
 $Result1 = mysql_query($updateSQL, $luis) or die(mysql_error());

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
 $updateSQL = sprintf("UPDATE login SET nomeutilizador=%s, email=%s, passe=%s, sexo=%s, pais=%s, datanascimento=%s WHERE nome=%s",
				   GetSQLValueString($_POST['nomeutilizador'], "text"),
				   GetSQLValueString($_POST['email'], "text"),
				   GetSQLValueString($_POST['passe'], "text"),
				   GetSQLValueString($_POST['sexo'], "text"),
				   GetSQLValueString($_POST['pais'], "text"),
				   GetSQLValueString($_POST['datanascimento'], "text"),
				   GetSQLValueString($_POST['nome'], "text"));

 mysql_select_db($database_luis, $luis);
 $Result1 = mysql_query($updateSQL, $luis) or die(mysql_error());

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
 $updateSQL = sprintf("UPDATE login SET nome=%s, email=%s, passe=%s, sexo=%s, pais=%s, datanascimento=%s WHERE nomeutilizador=%s",
				   GetSQLValueString($_POST['nome'], "text"),
				   GetSQLValueString($_POST['email'], "text"),
				   GetSQLValueString($_POST['passe'], "text"),
				   GetSQLValueString($_POST['sexo'], "text"),
				   GetSQLValueString($_POST['pais'], "text"),
				   GetSQLValueString($_POST['datanascimento'], "text"),
				   GetSQLValueString($_POST['nomeutilizador'], "text"));

 mysql_select_db($database_luis, $luis);
 $Result1 = mysql_query($updateSQL, $luis) or die(mysql_error());

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
 $updateSQL = sprintf("UPDATE inscricao SET Idade=%s, BI=%s, Localidade=%s, Email=%s, Contato=%s, Nick=%s, Equipa=%s WHERE Nome=%s",
				   GetSQLValueString($_POST['Idade'], "int"),
				   GetSQLValueString($_POST['BI'], "int"),
				   GetSQLValueString($_POST['Localidade'], "text"),
				   GetSQLValueString($_POST['Email'], "text"),
				   GetSQLValueString($_POST['Contato'], "int"),
				   GetSQLValueString($_POST['Nick'], "text"),
				   GetSQLValueString($_POST['Equipa'], "text"),
				   GetSQLValueString($_POST['Nome'], "text"));

 mysql_select_db($database_luis, $luis);
 $Result1 = mysql_query($updateSQL, $luis) or die(mysql_error());

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

mysql_select_db($database_luis, $luis);
$query_Recordset1 = "SELECT * FROM login";
$Recordset1 = mysql_query($query_Recordset1, $luis) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_luis, $luis);
$query_Recordset2 = "SELECT * FROM login";
$Recordset2 = mysql_query($query_Recordset2, $luis) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>

<!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>
<link rel="shortcut icon" href="imagens/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url();
background-color: #FFFFFF;
}
.style7 {color: #FFFFFF; font-size: 36px;}
a:link {
color: #999999;
text-decoration: none;
}
a:visited {
color: #999999;
text-decoration: none;
}
a:hover {
color: #999999;
text-decoration: none;
}
a:active {
color: #999999;
text-decoration: none;
}
body,td,th {
font-family: sans-serif;
color: #999999;
}
.style10 {color: #999999}
-->
</style></head>

<body>
<table width="1228" border="0" align="center">
 <tr>
<td colspan="6" rowspan="4"><img src="imagens/testeheader.png" alt="teste" width="964" height="136" /></td>
<td colspan="3"><table width="129" border="0" align="right">
  <tr>
	<td width="51"><a href="login.php">Login</a> |</td>
	<td width="61"><a href="registar.php">Registar</a></td>
  </tr>
</table></td>
 </tr>
 <tr>
<td colspan="3"> </td>
 </tr>
 <tr>
<td width="81"><a href="https://www.facebook.com/EbsfcLanParty"><img src="imagens/facebook logo.png" alt="fb" width="80" height="80" border="0" /></a></td>
<td width="83"><img src="imagens/twitchtv.jpg" alt="tw" width="80" height="26" /></td>
<td width="80"><img src="imagens/youtubelogo.png" alt="you" width="80" height="71" /></td>
 </tr>
 <tr>
<td colspan="3"> </td>
 </tr>
 <tr>
<td width="55">Home</td>
<td width="64">Sobre</td>
<td width="91">Inscrições</td>
<td width="90">Torneios</td>
<td width="648">Contatos</td>
<td colspan="4"> </td>
 </tr>
</table>
<p align="left" class="style7 style10">Alterar</p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" class="style10">
  <table align="center">
	<tr valign="baseline">
	  <td nowrap align="right"><strong>Nome:</strong></td>
	  <td></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"><strong>Idade:</strong></td>
	  <td><input type="text" name="Idade" value="" size="32"></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"><strong>BI:</strong></td>
	  <td><input type="text" name="BI" value="" size="32"></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"><strong>Localidade:</strong></td>
	  <td><input type="text" name="Localidade" value="" size="32"></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"><strong>Email:</strong></td>
	  <td><input type="text" name="Email" value="" size="32"></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"><strong>Contato:</strong></td>
	  <td><input type="text" name="Contato" value="" size="32"></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"><strong>Nick:</strong></td>
	  <td><input type="text" name="Nick" value="" size="32"></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"><strong>Equipa:</strong></td>
	  <td><input type="text" name="Equipa" value="" size="32"></td>
	</tr>
	<tr valign="baseline">
	  <td nowrap align="right"> </td>
	  <td><input type="submit" value="Update record"></td>
	</tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="Nome" value="<?php echo $row_Recordset2['Nome']; ?>">
</form>
<p class="style10"> </p>
<p> </p>
<table width="200" border="1" align="center">
 <tr>
<td><div align="center">
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1220" height="140">
	<param name="movie" value="imagens/barrapublicidade.swf" />
	<param name="quality" value="high" />
	<embed src="imagens/barrapublicidade.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1220" height="140"></embed>
  </object>
</div></td>
 </tr>
</table>
<p> </p>
</body>
</html>

<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>
Link to comment
Share on other sites

Dica:

A tua próxima ação irá ser pegar no dreamwiever, deita-lo fora, pegar num editor de texto bom, tão bom ou melhor que o notepad++ e fazer tudo de novo.

A sério, já tenho pesadelos com a quantidade de perguntas com este tipo de código.

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.