0

I'm getting this error in my variables on lines 26 and 27. I have been searching for the problem itself, some people say that the variables are not initialized. Althought I think they are. Also I saw people saying to use isset() / !empty() but I don't understand that, and what it does.

<?php

$nome = $_POST['nome'];   //26
$preco = $_POST['preco'];  //27

if(count($_FILES) > 0) {
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
mysql_connect("localhost", "crc", "root");
mysql_select_db ("crc");
$imgData =addslashes(file_get_contents($_FILES['userImage'['tmp_name']));
$sql = "INSERT INTO fios (nome,preco,imagem)VALUES('$nome','$preco','{$imgData}')"; 
$current_id = mysql_query($sql) or die("<b>Erro:</b> Problema na imagem inserida!<br/>" . mysql_error());
if(isset($current_id)) {
header("Location: veradmin.php");
}}}
?>

<!DOCTYPE html>
<html>
<title>Inserir</title>
</head>
<body>

<form name="frmImage" enctype="multipart/form-data" action="" method="post" class="frmImageUpload">

<div align="center">          

            </p><tr>
              <td width="321"><strong>Nome/Descricao:</strong></td>
              <td width="102" align="left">
                 <input type="text" name="nome"  value="" size="40" />

              </td>
            </tr><p>

            </p><tr>
              <td width="321"><strong>Preco:</strong></td>
              <td width="102" align="left">
                 <input type="text" maxlength="9" name="preco"  value="" size="20" />

              </td><p>
            </p></tr>

            <input name="userImage" type="file" class="inputFile" /><p>

            </p><input type="submit" value="Inserir Registo" class="btnSubmit" />

</form>
</div>
</body>
</html> 
fabimetabi
  • 124
  • 11

1 Answers1

1

This issue happened because in the first load $_POST['nome'] and $_POST['preco'] is empty and these indexes does not exists.

In this cases you should check with !empty to run this lines:

if(!empty($_POST['nome']) && !empty($_POST['preco']))
{
      if(count($_FILES) > 0) {
           ...
      }
}

At this time if you post your form or not these codes will run which is root cause of showing these notices

Majid Abbasi
  • 1,531
  • 3
  • 12
  • 22