Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- $db_host="localhost";
- $db_user="root";
- $db_password="";
- $db_name="versandhandel";
- $db=new PDO("mysql:host=$db_host; dbname=$db_name; charset=utf8", $db_user, "");
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
- print_r($_POST);
- print_r($_GET);
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title></title>
- </head>
- <body>
- <h3>crud</h3>
- <form method="POST" action="">
- <input type="text" name="ID" value="" /><br />
- <input type="submit" name="new" value="Neuer Datensatz" />
- </form>
- <table border="3">
- <tr>
- <td>Neue ID</td>
- <td>ID</td>
- <td>Nachname</td>
- <td>Vorname</td>
- <td>Strasse</td>
- <td>PLZ</td>
- <td>Ort</td>
- </tr>
- <?PHP
- $sql="SELECT * FROM tkunde";
- $stmt=$db -> prepare($sql);
- //$stmt->bindValue('fbn',$_POST['benutzername'],PDO::PARAM_STR);
- //$stmt->bindValue('fpw',$_POST['passwort'],PDO::PARAM_STR);
- $stmt -> execute();
- $anzahl=$stmt->rowCount();
- while($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
- echo "<tr>";
- ?> <td>
- <form method="POST" action="">
- <input type="text" name="ID" />
- </form>
- </td>
- <?PHP
- echo "<td>" .$row['KU_ID'] ."</td>";
- echo "<td>" .$row['Nachname'] ."</td>";
- echo "<td>" .$row['Vorname'] ."</td>";
- echo "<td>" .$row['Strasse'] ."</td>";
- echo "<td>" .$row['PLZ'] ."</td>";
- echo "<td>" .$row['Ort'] ."</td>";
- echo "<tr>";
- }
- if(isset($_POST['new'])){
- ?>
- <form method="POST" action="">
- Nachname: <input type="text" name="nn" />
- Vorname: <input type="text" name="vn" />
- Strasse: <input type="text" name="strasse" />
- PLZ: <input type="text" name="plz" />
- Ort: <input type="text" name="ort" />
- <br /><br />
- <input type="submit" name="send" value="Absenden" />
- <br /><br />
- </form>
- <?PHP
- }
- if(isset($_POST['send'])){
- if($_POST['nn']!=""){
- $sql1="INSERT INTO tkunde (Nachname, Vorname, Strasse, Plz, Ort) VALUES (:nn, :vn, :strasse, :plz, :ort)";
- $stmt1=$db -> prepare($sql1);
- $stmt1->bindValue('id',$_POST['ID'],PDO::PARAM_STR);
- $stmt1->bindValue('nn',$_POST['nn'],PDO::PARAM_STR);
- $stmt1->bindValue('vn',$_POST['vn'],PDO::PARAM_STR);
- $stmt1->bindValue('strasse',$_POST['strasse'],PDO::PARAM_STR);
- $stmt1->bindValue('plz',$_POST['plz'],PDO::PARAM_STR);
- $stmt1->bindValue('ort',$_POST['ort'],PDO::PARAM_STR);
- $stmt1 -> execute();
- }
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement