1

i want to get value of input of my form via $_post in my insert page but my problem is that i get error massage:undefined index:track_code and i cant get value of it.the names is same what is problem? this is my problem why stackoverflow want more detail. this is all detail

<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
</form>


<form action="insert.php" method="post" class="form-horizontal form-checkout">
 <div class="control-group">
  <label class="control-label" for="firstName">نام<span class="red-clr bold">*</span></label>
  <div class="controls">
  <input name="first_name" type="text" id="firstName" class="span4" >
  </div>
  </div>
  <div class="control-group">
  <label class="control-label" for="lastName">نام خانوادگی<span class="red-clr bold">*</span></label>
  <div class="controls">
  <input name="last_name" type="text" id="lastName" class="span4">
  </div>
  </div>
  <input name="submit" type="submit" class="btn btn-success" value="خرید"     style="width: 66px"/>
  </form>

  <form action="insert.php" method="post">
  <input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
  </form>


  <?php
  $track_code = $_POST['track_code'];
  ?>
sinak
  • 222
  • 6
  • 19

3 Answers3

0

Try Putting the PHP code on the form. as given below.

<?php
  if (isset($_POST['submit'])) {
    $track_code = $_POST['track_code'];
  }
?>
<form action="your_page.php" method="post">
   <input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd; ?>" style="width: auto;height: auto" readonly />
  <input name="submit" type="submit" />
</form>

It will execute the whole file as PHP. The first time you open it, $_POST['submit'] won't be set because the form has not been sent. Once you click on the submit button, it will print the information.

Disabled controls never post on server. So make it readonly or hidden.

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
0

Set this one code in your form

<form action="insert.php" method="post">
  <input name="track_code" type="text" class="tiny-size" value="<?php echo ($track_code_rnd)?$track_code_rnd:'';?>" style="width: auto;height: auto" disabled />
</form>
0

Remove disable tag from your input code. Disable controls wont be posted on server. for that you can make it readonly or make it hide

Tejas Patel
  • 61
  • 1
  • 5