0

I am looping through rows of mysql data as array's.

All the data goes into the labels fine as single values, yet when the edit button is used it does "updatecompany.php?id=1&id=2 when it should just be ?id=1 or ?id=2.

What am I doing wrong for that single field? Why is it pulling both values from the rows and not just one like the rest of the echo's.

  <?php
    $details = \Ar\login::getCompanys();
    foreach($details as $value){
      echo "<div class='container'><div class='well'>";
      echo "ID: " . $value['id'];
      echo "<br>";
      echo "Company: " . $value['name'];
      echo "<br>";
      echo "Logo: " . $value['logo'];
      echo "<br>";
      echo "Url: " . $value['site'];
      echo "<br>";
      echo "EST: " . $value['est'];
      echo "<br>";
      echo "Info: " . $value['info'];
      echo "<br><br>";
      echo "<form action='updatecompany.php' method='get'><input type='hidden' name='id' value='". $value['id'] ."'/><button type='submit' class='btn btn-lg btn-primary'>Edit</button>";
      echo "</div></div>";
      echo "<br>";
    }
    //print_r($details);
  ?>
3
  • 2
    You never close your <form> so you have one huge form with child forms. Commented Jan 3, 2017 at 21:00
  • that was the cause, jeez thanks man. Commented Jan 3, 2017 at 21:03
  • Okay, I've moved that as an answer. Commented Jan 3, 2017 at 22:15

3 Answers 3

1

You never close your form so you are making multiple forms. You also don't need multiple echos either. Something like:

echo "<div class='container'><div class='well'>
     ID: " . $value['id'] .
     "<br>
     Company: " . $value['name'] . 
     "<br>
     Logo: " . $value['logo'] . 
     "<br>
     Url: " . $value['site'] .
     "<br>
     EST: " . $value['est'] .
     "<br>
     Info: " . $value['info'] .
     "<br><br>
     <form action='updatecompany.php' method='get'>
           <input type='hidden' name='id' value='". $value['id'] ."'/>
           <button type='submit' class='btn btn-lg btn-primary'>Edit</button>
    </form> /* <-- guess */       
    </div>
    </div>
    <br>";

Should resolve the issue (the closing form location is a guess).

Sign up to request clarification or add additional context in comments.

Comments

0
</form>

Never closed the form out causing it to go nuts.

Comments

0

you should close the <form> tag in your code. So your form line should look like:

echo "<form action='updatecompany.php' method='get'><input type='hidden' name='id' value='". $value['id'] ."'/><button type='submit' class='btn btn-lg btn-primary'>Edit</button></form>";

Then you'll get the correct results.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.