Why does it appear undifined index?

Asked

Viewed 45 times

-2

I have a code that sends some information but it’s not sending the full copies I don’t know why. I send everything else up to the file except the total copies. I used an echo="$totalcopias" instead the value of the variable and the value ta la but when I try to send it is undifined index.

    $mailto = $_POST['mailto'];
    $mailSub = $_POST['mailsub'];
    $escola=$_POST['escola']; 
    $nome = $_POST['nome'];
    $processo=$_POST['processo']; 
    $disciplina=$_POST['disciplina']; 
    $a4cor = $_POST['a4cor'];
    $a4preto = $_POST['a4preto'];
    $a3cor=$_POST['a3cor'];
    $a3preto=$_POST['a3preto'];
    $impressao=$_POST['impressao'];  
    $observacoes=$_POST['observacoes'];
    $totalcopias=$a4cor + $a4preto + $a3cor + $a3preto;
    $target = "ficheiros/".basename($_FILES['ficheiro']['name']);
$mail ->Body='<h2>Escola: '.$_POST['escola'].'<br>Nome: '.$_POST['nome'].'<br>Processo: '.$_POST['processo'].'<br>Email: '.$_POST['email'].'<br>Disciplina: '.$_POST['disciplina'].'<br>Fotocópias A4 a cor: '.$_POST['a4cor'].'<br>Fotocópias A4 a preto: '.$_POST['a4preto'].'<br>Fotocópias A3 a cor: '.$_POST['a3cor'].'<br>Fotocópias A3 a preto: '.$_POST['a3preto'].'<br>Impressão: '.$_POST['impressao'].'<br>Observacões: '.$_POST['observacoes'].'<br>Total de fotocópias: '.$_POST['totalcopias'].'</h2>';
  • Check if in your form it contains this name

  • $totalcopias is a variable, does not exist in the superglobal $_POST['totalcopias']. In fact, none of the variables you defined you used afterwards, which made no sense at all.

  • I have an input with value 0

  • These variables are only for sending because I send to the email and to a database

  • declares $valuables = 0; before

1 answer

1


Failed to declare and inhibit it

$totalcopias = 0;
$mailto = $_POST['mailto'];
    $mailSub = $_POST['mailsub'];
    $escola=$_POST['escola']; 
    $nome = $_POST['nome'];
    $processo=$_POST['processo']; 
    $disciplina=$_POST['disciplina']; 
    $a4cor = $_POST['a4cor'];
    $a4preto = $_POST['a4preto'];
    $a3cor=$_POST['a3cor'];
    $a3preto=$_POST['a3preto'];
    $impressao=$_POST['impressao'];  
    $observacoes=$_POST['observacoes'];
    $totalcopias=$a4cor + $a4preto + $a3cor + $a3preto;
    $target = "ficheiros/".basename($_FILES['ficheiro']['name']);
  • undifined index the same

  • hi? I don’t understand what you mean... you make the same mistake?

  • yes I tried to change the name of the variable tmb

  • error appears here . $_POST['totalcopias']. ' that ta undifined but I’ve already used an echo to know the value and shows the right value

  • checks that all values coming from the form are equal to those that send to that total copies

  • $a4cor + $a4preto + $a3cor + $a3preto;.

  • $totalcopias=$a4cor + $a4preto + $a3cor + $a3preto; echo "$totalcopias";

  • 66 Notice: Undefined index: totalcopias in C: xampp htdocs teste enviar.php on line 71

  • What’s the line 71? that $totalcopias=$a4cor + $a4preto + $a3cor + $a3preto;

  • if you just pull up a chat there

  • line 71 whole $mail ->Body='<H2>School: '.$_POST['school']. '<br>Name: '.$_POST['name']. '<br>Process: '.$_POST['process']. '<br>Email: '.$_POST['email']. '<br>Discipline: '.$_POST['discipline']. '<br>Photocopies A4 to color: '.$_POST['a4cor']. '<br>A4 photocopies in black: '.$_POST['a4preto']. '<br>A3 photocopies in color: '.$_POST['a3cor']. '<br>A3 photocopies in black: '.$_POST['a3preto']. '<br>Printing: '.$_POST['impression']. '<br>Remarks: '.$_POST['observations']. '<br>Total photocopies: '.$_POST['totalcopies']. '</H2>';

  • Note the Total of photocopies: '.$_POST['totalcopias'].... you are not using a post from it to be able to add... you are using it internally with the variable declaration $totalcopias=$a4cor + $a4preto + $a3cor + $a3preto; ...you have to put $totalcopias and not $_POST['totalcopias']

  • Solved your problem?

  • yes now it worked

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.