Problème lors de l'ajout dans ma bdd

kdidot
Invité n'ayant pas de compte PHPfrance

06 sept. 2013, 18:46

Bonjour,

j'ai enfait un petit problème avec l'ajout d'une nouvelle entrée dans ma base de données. J'aimerais enfait tout simplement ajouter une image, qui sera redimensionné à l'upload. Le redimensionnement et tout marche. C'est juste que lorsque j'essaye d'ajouter une nouvelle entrée, je reçois le message suivant:

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: photo in C:\wamp\www\martinjakob\admin\add_photos\add_photos_travaux.php on line 46


Ce qui est étonnant parce que pour mes autres pages tout fonctionne. Voici le code php de ma page. Cela fait 2h que j'essaye de trouver l'erreur, sans succès.
Si vous pouviez m'aider et m'expliquer l'erreur ce ne serait pas refus.

Merci pour tout et pour ce forum :).

Kévin
<?php require_once('../../Connections/conn.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']);
}

// Test si le formulaire a bien été envoyé
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) 
{
	//récupère et redimensionne la photo
	$photodir='../../gallery/images/';
	$photo="";	
	
	$type_photo = $_FILES['photo']['type'];
	//vérifie que la photo soit au bon format
	if(!(strstr($type_photo,'jpg') or strstr($type_photo,'jpeg') or strstr($type_photo,'bmp') or strstr($type_photo,'gif') or strstr($type_photo,'png')))
	{
		exit("L'image n'est pas compatible ou est trop lourde.");
	}
	//vérifie que l'upload s'est bien passée
		$the_image=$photodir.$_FILES['photo']['name'];
		$the_image_big=$photodir."big_".$_FILES['photo']['name'];
		
		$i="";
		while(file_exists($the_image_big)){
			$i+=1;
			$the_image=$photodir.$i.$_FILES['photo']['name'];
			$the_image_big=$photodir."big_".$i.$_FILES['photo']['name'];
		}
		
		if(move_uploaded_file($_FILES['photo']['tmp_name'], $the_image))
		{
		$photo=$i.$_FILES['photo']['name'];
				
		list($width, $height, $type, $attr) = getimagesize($photodir.$photo);
				
		// si la vignette est horizontale
		if($width>=$height)
		{
			creation_vignette($photo , 96 , 250 , $photodir , $photodir , "small_");
			creation_vignette($photo , 400 , 1000 , $photodir , $photodir , "big_");
		}
		// si la vignette est verticale
		if($width<=$height)
		{
			creation_vignette($photo , 96 , 250 , $photodir , $photodir , "small_");
			creation_vignette($photo , 400 , 1000 , $photodir , $photodir , "big_");
		}
		//efface l'originale
		if($photo!="") 
		{
			chmod($photodir.$photo,0777);
	  		unlink($photodir.$photo);
		}
	}
	$insertSQL = sprintf("INSERT INTO photos (id, photo) VALUES (%s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($photo, "text"));
					   
  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());

  $insertGoTo = "gestion_photos_travaux.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_conn, $conn);
$query_travaux = "SELECT * FROM travaux ORDER BY nom ASC";
$travaux = mysql_query($query_travaux, $conn) or die(mysql_error());
$row_travaux = mysql_fetch_assoc($travaux);
$totalRows_travaux = mysql_num_rows($travaux);
?>

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

06 sept. 2013, 21:01

salut,


a priori le champ de type file, dans le formulaire, ne s'appel pas "photo".


@+
Il en faut peu pour être heureux ......

kdidot
Invité n'ayant pas de compte PHPfrance

07 sept. 2013, 12:16

Merci pour ta réponse!

Voici le formulaire de ma page dont le champs FILE porte bien le nom photo.
Je ne comprends donc pas d'où vient l'erreur.
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
          <table id="tablecorps">
            <tr valign="baseline">
            	<td nowrap="nowrap" align="right">Nom:</td>
				<td><select name="tra_id" STYLE="width:150px">
					<?php 
					do 
					{  
						echo '<option value="'.$row_travaux['id'].'">'.$row_travaux['nom'].'</option>';
					} 
					while ($row_travaux = mysql_fetch_assoc($travaux));
					?>
				</select></td>
            </tr>
            <tr>
            	<td nowrap="nowrap" align="right">Photo:</td>
                <td><label><input name="photo" type="file" id="photo" onchange="test_image()" size="32"/></label></td>
            </tr>
            <tr valign="baseline">
            	<td nowrap="nowrap" align="right">&nbsp;</td>
            	<td><input type="submit" value="Ajouter" /></td>
            </tr>
          </table>
          <input type="hidden" name="id" value="" />
          <input type="hidden" name="MM_insert" value="form1" />
        </form>

kdidot
Invité n'ayant pas de compte PHPfrance

09 sept. 2013, 16:57

Je n'ai toujours pas trouver la solution à mon problème, après avoir essayé de changer le nom de la variable photo et plusieurs autres manipulations, mon problème est toujours actuel.

kdidot
Invité n'ayant pas de compte PHPfrance

10 sept. 2013, 02:51

Merci quand même. J'ai finalement trouvé. C'était le enctype="multipart/form-data" dans mon formulaire.