par
Chile » 21 mars 2006, 23:30
si je l'ai ! j'avais deja lu le tuto
par contre j'ai inseré le code, et m'indique une erreur
">
Warning: mysql_free_result(): 3 is not a valid MySQL result resource in /home.2/webaplic/www/exemple/majpays2.php on line 152
et je n'ai pas de ligne 152 !
et puis la photo deja presente dans ma table, disparait suite a la mise a jour sans rien rentrer dans le champ photo...
est ce que je dois agir de meme sur la fonction move_upload_file ?
je suis perdu
voici mon code total avec la modif:
<?php require_once('../Connections/pays.php'); ?>
<?php
//Script Upload
//on vérifies que le champ est bien rempli:
if(!empty($_FILES["photo"]["name"]))
{
//nom du fichier choisi:
$nomFichier = $_FILES["photo"]["name"] ;
//nom temporaire sur le serveur:
$nomTemporaire = $_FILES["photo"]["tmp_name"] ;
//type du fichier choisi:
$typeFichier = $_FILES["photo"]["type"] ;
//poids en octets du fichier choisit:
$poidsFichier = $_FILES["photo"]["size"] ;
//code de l'erreur si jamais il y en a une:
$codeErreur = $_FILES["photo"]["error"] ;
//chemin qui mène au dossier qui va contenir les fichiers upload:
$chemin = "./images/" ;
if(move_uploaded_file($nomTemporaire, $chemin.$nomFichier))
echo("<br>l'upload a réussi");
else
echo("<br>l'upload a échoué");
}//fin if
else
{
echo("Vous n'avez pas choisit de fichier!!<br>") ;
echo("<a href=\"./choix_fichier.html\">Retour</a>") ;
}//fin else
?>
<?php
$nomFichier = ""; // déclaration des variables
$chemin = "";
if(!empty($_FILES["photo"]["name"])) {
$nomFichier = $_FILES["photo"]["name"] ; // renseignement des variables
$chemin = "./images/" ;
}
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 bpays SET pays=%s, site=%s, photo=%s, chemin=%s WHERE id=%s",
GetSQLValueString($_POST['pays'], "text"),
GetSQLValueString($_POST['site'], "text"),
GetSQLValueString($nomFichier, "text"), // utilisation des variables nom
GetSQLValueString($chemin, "text"), // et chemin
GetSQLValueString($_POST['id'], "int"));
if($nomFichier!="")
$sql.= ", fichier = '$nomFichier'"; // on ne remplace la valeur que s'il y en a une nouvelle
mysql_select_db($database_pays, $pays);
$Result1 = mysql_query($updateSQL, $pays) or die(mysql_error());
$updateGoTo = "affichageimag.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_majpays = "1";
if (isset($_GET['id'])) {
$colname_majpays = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_pays, $pays);
$query_majpays = sprintf("SELECT * FROM bpays WHERE id = %s", $colname_majpays);
$majpays = mysql_query($query_majpays, $pays) or die(mysql_error());
$row_majpays = mysql_fetch_assoc($majpays);
$totalRows_majpays = mysql_num_rows($majpays);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document sans titre</title>
</head>
<body>
<div align="center">
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Pays:</td>
<td><input type="text" name="pays" value="<?php echo $row_majpays['pays']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Site:</td>
<td><input type="text" name="site" value="<?php echo $row_majpays['site']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Photo:</td>
<td><input name="photo" type="file" id="photo" value="<?php echo $row_majpays['photo']; ?>"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Mettre à jour l'enregistrement"></td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo $row_majpays['id']; ?>">
<input type="hidden" name="chemin" value="<?php echo $row_majpays['chemin']; ?>">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="id" value="<?php echo $row_majpays['id']; ?>">
</form>
<p> </p>
</div>
</body>
</html>
<?php
mysql_free_result($majpays);
?>
si je l'ai ! j'avais deja lu le tuto :)
par contre j'ai inseré le code, et m'indique une erreur
[php]">
Warning: mysql_free_result(): 3 is not a valid MySQL result resource in /home.2/webaplic/www/exemple/majpays2.php on line 152[/php]
et je n'ai pas de ligne 152 !
et puis la photo deja presente dans ma table, disparait suite a la mise a jour sans rien rentrer dans le champ photo... :cry:
est ce que je dois agir de meme sur la fonction move_upload_file ?
je suis perdu :shock:
voici mon code total avec la modif:
[php]<?php require_once('../Connections/pays.php'); ?>
<?php
//Script Upload
//on vérifies que le champ est bien rempli:
if(!empty($_FILES["photo"]["name"]))
{
//nom du fichier choisi:
$nomFichier = $_FILES["photo"]["name"] ;
//nom temporaire sur le serveur:
$nomTemporaire = $_FILES["photo"]["tmp_name"] ;
//type du fichier choisi:
$typeFichier = $_FILES["photo"]["type"] ;
//poids en octets du fichier choisit:
$poidsFichier = $_FILES["photo"]["size"] ;
//code de l'erreur si jamais il y en a une:
$codeErreur = $_FILES["photo"]["error"] ;
//chemin qui mène au dossier qui va contenir les fichiers upload:
$chemin = "./images/" ;
if(move_uploaded_file($nomTemporaire, $chemin.$nomFichier))
echo("<br>l'upload a réussi");
else
echo("<br>l'upload a échoué");
}//fin if
else
{
echo("Vous n'avez pas choisit de fichier!!<br>") ;
echo("<a href=\"./choix_fichier.html\">Retour</a>") ;
}//fin else
?>
<?php
$nomFichier = ""; // déclaration des variables
$chemin = "";
if(!empty($_FILES["photo"]["name"])) {
$nomFichier = $_FILES["photo"]["name"] ; // renseignement des variables
$chemin = "./images/" ;
}
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 bpays SET pays=%s, site=%s, photo=%s, chemin=%s WHERE id=%s",
GetSQLValueString($_POST['pays'], "text"),
GetSQLValueString($_POST['site'], "text"),
GetSQLValueString($nomFichier, "text"), // utilisation des variables nom
GetSQLValueString($chemin, "text"), // et chemin
GetSQLValueString($_POST['id'], "int"));
if($nomFichier!="")
$sql.= ", fichier = '$nomFichier'"; // on ne remplace la valeur que s'il y en a une nouvelle
mysql_select_db($database_pays, $pays);
$Result1 = mysql_query($updateSQL, $pays) or die(mysql_error());
$updateGoTo = "affichageimag.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_majpays = "1";
if (isset($_GET['id'])) {
$colname_majpays = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_pays, $pays);
$query_majpays = sprintf("SELECT * FROM bpays WHERE id = %s", $colname_majpays);
$majpays = mysql_query($query_majpays, $pays) or die(mysql_error());
$row_majpays = mysql_fetch_assoc($majpays);
$totalRows_majpays = mysql_num_rows($majpays);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document sans titre</title>
</head>
<body>
<div align="center">
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Pays:</td>
<td><input type="text" name="pays" value="<?php echo $row_majpays['pays']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Site:</td>
<td><input type="text" name="site" value="<?php echo $row_majpays['site']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Photo:</td>
<td><input name="photo" type="file" id="photo" value="<?php echo $row_majpays['photo']; ?>"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Mettre à jour l'enregistrement"></td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo $row_majpays['id']; ?>">
<input type="hidden" name="chemin" value="<?php echo $row_majpays['chemin']; ?>">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="id" value="<?php echo $row_majpays['id']; ?>">
</form>
<p> </p>
</div>
</body>
</html>
<?php
mysql_free_result($majpays);
?>[/php]