begin process at 2012 05 31 04:29:54
  Trouver un code source :
 
dans
 
Accueil > Forum > 

PHP

 > 

Base de données

 > 

MySQL

 > 

PHP update problem


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

PHP update problem

vendredi 17 juin 2011 à 21:09:31 | PHP update problem

anastasia0181

HI,
I have an application for creating accounts with :
"Name" / "email"/ "password" (I use sha1 to hash it) , I created a diferent page to update these info, but if i update name or email only the password gets encrypted a second time.

--------------------------------------------------------------------------

Below is my code for the update page, I want to update the password only when it is changed.

***********************************************************************
<?php require_once('../../Connections/myDB.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"] == "loginForm")) {
$updateSQL = sprintf("UPDATE userTbl SET Name=%s, Email=%s, Password=sha(%s) WHERE id=%s",
GetSQLValueString($_POST['Name'], "text"),
GetSQLValueString($_POST['Email'], "text"),
GetSQLValueString($_POST['Password'], "text"),
GetSQLValueString($_POST['userId'], "int"));

mysql_select_db($database_myDB, $myDB);
$Result1 = mysql_query($updateSQL, $myDB) or die(mysql_error());

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

$colname_rsUp = "1";
if (isset($_GET['id'])) {
$colname_rsUp = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_myDB, $myDB);
$query_rsUp = sprintf("SELECT * FROM userTbl WHERE id = %s", $colname_rsUp);
$rsUp = mysql_query($query_rsUp, $myDB) or die(mysql_error());
$row_rsUp = mysql_fetch_assoc($rsUp);
$totalRows_rsUp = mysql_num_rows($rsUp);
?>

<form action="<?php echo $editFormAction; ?>" id="updateForm" name="loginForm" method="POST">

<table width="280" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<th height="34" width="85"><div align="left" >Name : </div></th>
<td colspan="4">

<input name="Name" type="text" class="textfield" id="Name" value="<?php echo $row_rsUp['Name']; ?>" size="30" />

</td>
</tr>
<tr>
<th height="34" width="85"><div align="left" >Email:</div></th>
<td colspan="4">
<span id="two">
<input name="Email" type="text" class="textfield" id="Email" value="<?php echo $row_rsUp['Email']; ?>" size="30" />

</td>
</tr>
<tr>
<th height="34" width="85"><div align="left" >Password:</div></th>
<td colspan="4">

<input name="Password" type="password" class="textfield" id="Password" value="<?php echo $row_rsUp['Password']; ?>" size="30" />

</td>
</tr>
<tr>
<td>&nbsp;</td>

<td width="61">&nbsp;</td>
<td width="122" align="right"><input type="submit" name="Submit" value="Update" /></td>
</tr>
</table>
<input name="userId" type="hidden" id="userId" value="<?php echo $row_rsUp['id']; ?>" />
<input type="hidden" name="MM_update" value="loginForm">
</form>
<?php
mysql_free_result($rsUp);
?>

**************************************************************************

Thank you.
samedi 18 juin 2011 à 16:26:10 | Re : PHP update problem

cod57

bonjour
try something like
a++
Code PHP :
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "loginForm")) { 
$a = sprintf("UPDATE userTbl SET Name=%s, Email=%s, Password=sha(%s) WHERE id='%s'", 
$b = sprintf("UPDATE userTbl SET Name=%s, Email=%s, WHERE id='%s'", 
GetSQLValueString($_POST['Name'], "text"), 
GetSQLValueString($_POST['Email'], "text"), 
GetSQLValueString($_POST['Password'], "text"), 
GetSQLValueString($_POST['userId'], "int")); 

$sql=sprintf("select * from userTbl where WHERE id='%s' ");
$r=mysql_fecth_row(mysql_query($sql));
//sha() or sha1() with php ... i thing ?
if($r['Password']===sha($_POST['password'])){
$updateSQL=$a;
}else{
$updateSQL=$b; //without password
}


mysql_select_db($database_myDB, $myDB); 
$Result1 = mysql_query($updateSQL, $myDB) or die(mysql_error());


Bonne programmation !
dimanche 19 juin 2011 à 19:16:13 | Re : PHP update problem

anastasia0181

Thank you very much, I will try it immediately, I truly appreciate your help


Cette discussion est classée dans : email, password, to, name, update


Répondre à ce message

Sujets en rapport avec ce message

Envoi MDP par mail: problème hash MD5 [ par arbilus ] Bonjours, me revoila avec du lourd, accrochez vous: [code=php] <input name="Submit" value="Envoyer Problème d'authentification [ par machmacha ] Bonjour a tous,j'ai un problème et j'espère que quelqu'un pourra m'aider a le résoudre voilà mon soucis:j'ai une page index.php ou il ya un rebrique d SVP Aidez-moi à conserver ce FORMULAIRE et ce CAPTCHA [ par Lisa3 ] Bonjour, je voudrais conserver [b]ce formulaire[/b] avec [b]ce captcha[/b], vérification de tous les champs et remercier par un mail automatique le v Premier affichage dans un tableau [ par abibol ] Bonjour à tous, voila c'est mon premier exercice en php5. J'ai trouvé ce code exécutable. Aide moi à trouver la solution la plus efficace. table ut aidez moi pb avec email !! [ par anisbs ] Salut je suis débutant en phpje commence a essayer quelques trucs mais la fonction mail ne fonctionne pas Il me sort un truc comme :Warning: mail(): email [ par henri12 ] salut j ai mis une fausse adresse j ai essayer if((mail($email, $objet, $contenu, "From: ".$from))==false){ echo $email; l email n est pas envoyer soucis de code... merci aux posteurs! [ par lelapinou_69 ] Mesdames, mlles, mrs, j'ai besoin d'une multitude d'yeux. Il se trouve qu'un erreur (qui m'affiche page blanche) s'est glissée dans ma page, sans que Mail php flash [ par fdgdfsgdfgd ] Bonjour a tous !J'ai creer un site flash avec une rubrique contact.Sur cette page 3 champs a remplir et 2 boutons, "effacer" qui fonctionne, et "envoy _Files [ ] ['name'] et magicquotes [ par Evangun ] Bonjour!je sais qu'on en parle souvent des magicquotes mais là...j'upload un fichier  c:\chemin\pho'to.jpg disons.et quand je demande $_FILES["image"]


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,373 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales