<form class="form-horizontal" method="post" action="success.php"> <input type="hidden" name="price" <?php echo 'value="'.$price. '"'; ?>> <input type="hidden" name="title" <?php echo 'value="'.$title. '"'; ?>> <input type="hidden" name="year" <?php echo 'value="'.$year. '"'; ?>> <input type="hidden" name="spec" <?php echo 'value="'.$spec. '"'; ?>> <input type="hidden" name="closes" <?php echo 'value="'.$closes. '"'; ?>> <div class="form-group"> <label for="name">Имя</label> <input type="text" class="form-control" id="name" name="name" required=""> </div> <div class="form-group"> <label for="phone">Телефон</label> <input type="phone" class="form-control" id="phone" name="phone" required=""> </div> <div class="form-group"> <button type="submit" class="btn btn-default">Заказать</button> </div> </form> 

The first page, a variable with a value, does not take on a value when transmitted to the second.

 <?php $name = $_POST['name']; $phone = $_POST['phone']; $title = $_POST['title']; $year = $_POST['year']; $spec = $_POST['spec']; $closes = $_POST['closes']; $price = $_POST['price']; $address = "test@gmail.com"; $article = "Защита картера двигателя"; $mes = "$article Имя: $name Телефон: $phone Характеристики: Марка: $title Год: $year Особенности: $spec Покрывает $closes Цена: $price"; $sub="Заказ обратного звонка!"; $send = mail ($address,$sub,$mes, "Content-type:text/plain; charset = utf-8 "); ?> 

Variable price does not accept value

  • What does it mean to not accept? Who exactly does not accept? Unclear nothing - andreymal February
  • @andreymal does not accept the value of the $ price variable - Alexander 2:19 pm

2 answers 2

To understand what is happening in your own code, you need to master some debugging techniques.

  1. Learn f12 to use developer tools in a browser (usually opens by pressing f12 ). There is an HTML inspector (Inspector tab) that will help you see what is in the hidden fields of the form and there is a network request log (Network tab), where you can see what you went to the server in the body of an HTTP request.
  2. var_dump is a PHP function that allows you to peek into a variable. Typing var_dump($_POST); you will see that you have in this array (including the keys, probably the price will be there, but it is equal to an empty string).

And one more tip for you. Do not output HTML using php (I mean echo ' value="..."' ). Insert only values ​​and be sure to escape them (read about XSS ): <input type="hidden" name="price" value="<?= htmlspecialchars($price) ?>"> (Small bonus: shorttag <?= Always works , and ; before the closing handle can be omitted, it will make your templates more readable).

    maybe $ _POST try)

     <form ... method="post"> ... $name = $_POST['name']; 
    • @angularva has not changed anything, the $ price variable does not accept the value - Alexander