0

I have made a database and a php to insert new information to the database. When I add some new information, everything works well, but when I want to change these information and update these, my input form look really different. This is my code for adding new information

<!DOCTYPE html>
<html lang="nl">
  <head>
    <meta charset="utf-8">
    <title>Klanten invoeren</title>
  </head>
  <body>
    <form action="SEDDopslaan.php" method="post">
      <p>
        Reisnummer: <br>
        <input name="reisnummer" type="text" size="30" tabindex="1">
      </p>
     
      <p>
        Land: <br>
        <select name="land">
        <option value="Nederland">Nederland
        <Option value="Duitsland">Duitsland
        <Option value="Frankrijk">Frankrijk
        <Option value="Belgie">Belgie
        </select>
      </p>
      
      <p>
        Plaats: <br>
        <input name="plaats" type="text" size="30" tabindex="3">
      </p>
      
      <p>
        Vertrekdatum: <br>
        <input name="vertrekdatum" type="date" size="30" tabindex="4">
        
      </p>
      
      <p>
        Retourdatum: <br>
        <input name="retourdatum" type="date" size="30" tabindex="5">
      </p>
      
      <p>
        Aantalpersonen: <br>
        <input name="aantalpersonen" type="text" size="30" tabindex="2">
      </p>
      
      <p>
        Prijs: <br>
        <input name="prijs" type="text" size="30" tabindex="2">
      </p>
      
      <p>
        Betaling voltooid: <br>
        <input name="betalingvoltooid" type="checkbox" value="Ja" size="30" tabindex="2">Ja
        <input name="betalingvoltooid" type="checkbox" value="Nee" size="30" tabindex="2">Nee
      </p>
      
      <p>
        <input type="submit" name="submit" value="Verstuur" title="Verstuur dit formulier" tabindex="6">
      </p>
    </form>
  </body>
</html>

And this is my code for changing information

<!DOCTYPE html>
<html lang="nl">
  <head>
    <meta charset="utf-8">
    <title>Klant wijzigen</title>
  </head>
  <body>
<?php
      // Maken van verbinding
      try {
        $db = new PDO('mysql:host=localhost;dbname=Reisbureau','root','');
      }
      catch(PDOException $e) {
        echo $e->getMessage();
}
      // De SQL opdracht
      // Hier wordt de klant geselecteerd om de gegevens op
      // te halen die je wilt wijzigen. Het klantnummer zit
      // in $_POST[verstopt]
      $sql = "SELECT * FROM boeking WHERE reisnummer = $_POST[verstopt]";
      $resultaat = $db->query($sql);
      // De klantgegevens worden in variabelen gestopt zodat
      // we ze in het formulier kunnen zien
      foreach($resultaat as $row) {
        $reisnummer = $row['reisnummer'];
        $land = $row['land'];
        $plaats = $row['plaats'];
        $vertrekdatum = $row['vertrekdatum'];
        $retourdatum  = $row['retourdatum'];
        $aantalpersonen  = $row['aantalpersonen'];
        $prijs  = $row['prijs'];
        $betalingvoltooid = $row['betalingvoltooid'];
}
      // Sluiten van verbinding
$db = NULL;
      echo "<form action='SEDDwijzigdefinitief.php'method='post'>
        <p>Reisnummer: <br>
        <input name='reisnummer' type='text' size='30'value=$reisnummer tabindex='1'>
        </p>
        <p>Land: <br>
        <input name='land' type='text' size='30' value=$land tabindex='2'>
        </p>
        <p>Plaats: <br>
        <input name='plaats' type='text' size='30' value=$plaats tabindex='3'>
        </p>
        <p>vertrekdatum: <br>
        <input name='vertrekdatum' type='date' size='30'value=$vertrekdatum tabindex='4'>
        </p>
        <p>Retourdatum: <br>
        <input name='retourdatum' type='date' size='30'value=$retourdatum tabindex='5'>
        </p>
        <p>Aantalpersonen: <br>
        <input name='aantalpersonen' type='text' size='30'value=$aantalpersonen tabindex='5'>
        </p>
        <p>Prijs: <br>
        <input name='prijs' type='text' size='30'value=$prijs tabindex='5'>
        </p>
        <p>Betalingvoltooid: <br>
        <input name='betalingvoltooid' type='text' size='30'value=$betalingvoltooid tabindex='5'>
        </p>
        <p><input type='submit' name='submit'value='Verstuur' title='Verstuur dit formulier' tabindex='6'>
</p>
</form>"
?>
  </body>
</html>

I would like to have exactly the same form in "Add information" as in "Change information"

0

2 Answers 2

1

Your code echo's your variables! You need to write like this:

echo "<input name='prijs' type='text' size='30'value='" . $prijs ."' tabindex='5'>";

So your code will echo the data from your database and not the $prijs plain as a string!

Hope this will help <3

Bonus:

If your $_POST[verstopt] should be a string then use single quotes '' in your query!

To pretend MySQL Injection, you could write your query like this:

 $verstopt = mysqli_real_escape_string($db, $_POST[verstopt]);
 $sql = "SELECT * FROM boeking WHERE reisnummer = $verstopt";

Change Checkbox value

You could use Javascript to change the value and then you post trough your <form> the input wehre the value is written in. Change the style from your input to style='display:none;' so that the user only can see the checkbox and not the input one which is gonna be used to send to your mysql query.

function test(){

var Result =  document.getElementById("checkbox").checked;
document.getElementById('ResultCheckbox').value = Result;

}
<input type="checkbox" id="checkbox" onclick="test();">
<input name="checkboxAnswer" id="ResultCheckbox" value="no">

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

2 Comments

Thanks, this works. But how do I insert for example a checkbox into this? In "toevoegen" there is a checkbox, so you can select "Ja" or "Nee" at "betalingvoltooid". Is it possible to add a checkbox into this form? So you can change "ja" into "nee" and save this?
If this worked, please checkmark my answer! I edited my post and adapted it to your question, with that checkbox situation. Hope this helps you out <3
1

Have you tried using delevoper tools of your browser to watch the HTML code?

Also, have you tried using quotes to enter your PHP variables? Something like:

<input name='reisnummer' type='text' size='30' value='".$reisnummer."' tabindex='1'>

What do you mean with form looking "different"?

1 Comment

I would like to have exactly the same look and working form as when you add new information. So "Edit information" look the same as "Add new information"

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.