Jump to content

DeckDekk

Members
  • Posts

    10
  • Joined

  • Last visited

DeckDekk's Achievements

Member

Member (2/5)

0

Reputation

  1. So I'm still banging my head over this one. I can't find the value needed to add into the table. And the only thing that gets added into the table are empty strings and integer values. I looked at what requinix said about the $teamname and $memberid values. But whatever value I try to assign to it, it doesn't insert into the database (unless I do 'teamname', then it inserts the string 'teamname' into the table). I also looked at the documentation but I can't apply that knowledge to my "insert dropdown data into different table" problem I changed everything to english for you guys, maybe that way you can point me into the right direction. Much appreciated! This is what I've got: <form name="dropdown" method="post"> <div class="page-header clearfix"> <h2 class="pull-left">Add teammember</h2> </div> <p>Use the dropdown to select which member you want to add to the team</p> <div class="container-fluid"> <div class="row"> <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL); $teamname = ''; $memberid = ''; $sql = "SELECT firstname, lastname, memberid FROM member ORDER BY surname"; $result = mysqli_query($conn, $sql); echo "<select id='teammember' name='teammember'>"; echo "<option>--select member--</option>"; while ($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['member'] . "'>" . $row['firstname'] . " " . $row['lastname'] . " " . $row['memberid'] . "</option>"; } echo "</select>"; if (isset($_POST["id"]) && !empty($_POST["id"])) { $id = $_POST["id"]; $stmt = $conn->prepare("INSERT INTO teammember (teamnname, memberid) VALUES (?,?)"); $stmt->bind_param('si', $param_teamname, $param_memberid); $param_teamname = $teamname; $param_memberid = $memberid; $stmt->execute(); } mysqli_close($conn); ?> <div> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" name="submit" class="btn btn-primary" value="Add"> </div> </div> </div> </form>
  2. Fixed it! The only thing I did was change $_POST["id"] to $_GET["id"] in the form. Thanks all for helping me with the thought proces : )
  3. You are probably right but from what I can tell the id value looks like the right data type ( the POST value for example is an int value like id=109). The corresponding column "lidnummer" takes smallint data values. And the code that provides the link to this delete form is: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Boast & Drive</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css"> <style type="text/css"> .wrapper{ width: 650px; margin: 0 auto; } .page-header h2{ margin-top: 0; } table tr td:last-child a{ margin-right: 15px; } </style> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div class="page-header clearfix"> <h2 class="pull-left">Teamleden</h2> <div class="btn-toolbar"> <a href="read.php" class="btn btn-primary btn-lg pull-right">Terug</a> </div> </div> <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL); //Verbinding maken met de database require_once "login.php"; $sql = "SELECT tl.teamnaam, tl.tl_ID, tl.lidnummer, l.voornaam, l.achternaam FROM teamlid tl JOIN lid l ON tl.lidnummer = l.lidnummer ORDER BY tl.teamnaam;"; if($result = mysqli_query($conn, $sql)) { if(mysqli_num_rows($result) > 0) { echo "<table class='table table-bordered table-striped'>"; echo "<thead>"; echo "<tr>"; echo "<th>Teamnaam</th>"; echo "<th>Tl_ID</th>"; echo "<th>Lidnummer</th>"; echo "<th>Voornaam</th>"; echo "<th>Achternaam</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; while($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['teamnaam'] . "</td>"; echo "<td>" . $row['tl_ID'] . "</td>"; echo "<td>" . $row['lidnummer'] . "</td>"; echo "<td>" . $row['voornaam'] . "</td>"; echo "<td>" . $row['achternaam'] . "</td>"; echo "<td>"; echo "<a href='update.php?id=". $row['lidnummer'] ."' title='Gegevens wijzigen' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>"; echo "<a href='deleteTeamLid.php?id=". $row['lidnummer'] ."' title='Lid verwijderen' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>"; echo "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; mysqli_free_result($result); } else{ echo "<p class='lead'><em>Er zijn geen gegevens om weer te geven.</em></p>"; } } else{ echo "De volgende fout is gevonden: " . mysqli_error($conn); } ?> <form name="dropdown" method="post"> <div class="page-header clearfix"> <h2 class="pull-left">Teamlid toevoegen</h2> </div> <p>Selecteer hieronder met behulp van het dropdown menu een lid welke je aan bovenstaand team wilt toevoegen</p> <div class="container-fluid"> <div class="row"> <?php $teamnaam = ''; $lidnummer = ''; $sql = "SELECT voornaam, achternaam, lidnummer FROM lid ORDER BY achternaam"; $result = mysqli_query($conn, $sql); echo "<select id='teamLid' name='teamLid'>"; echo "<option>--Selecteer Lid--</option>"; while ($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['lid'] . "'>" . $row['voornaam'] . " " . $row['achternaam'] . " " . $row['lidnummer'] . "</option>"; } echo "</select>"; if (isset($_POST["id"]) && !empty($_POST["id"])) { $id = $_POST["id"]; $stmt = $conn->prepare("INSERT INTO teamlid (teamnaam, lidnummer) VALUES (?,?)"); $stmt->bind_param('si', $param_teamnaam, $param_lidnummer); $param_teamnaam = $teamnaam; $param_lidnummer = $lidnummer; $stmt->execute(); } mysqli_close($conn); ?> <div> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" name="submit" class="btn btn-primary" value="Toevoegen"> </div> </div> </div> </form> </div> </div> </body> </html
  4. It redirects to the read.php page. There it shows all the current members of the "lid" table.
  5. Thanks! This is the structure of "lid" and "postcode": CREATE TABLE `lid` ( `lidnummer` smallint(6) NOT NULL, `voornaam` varchar(128) COLLATE utf8mb4_general_ci DEFAULT NULL, `achternaam` varchar(128) COLLATE utf8mb4_general_ci DEFAULT NULL, `postcode` varchar(128) COLLATE utf8mb4_general_ci DEFAULT NULL, `huisnummer` varchar(128) COLLATE utf8mb4_general_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE `postcode` ( `postcode` varchar(128) COLLATE utf8mb4_general_ci NOT NULL, `adres` varchar(128) COLLATE utf8mb4_general_ci DEFAULT NULL, `woonplaats` varchar(128) COLLATE utf8mb4_general_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
  6. Thanks! Still trying to get my head around it but I still haven't found a solution.
  7. Hello there! I've got this code: <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL); if (isset($_POST["id"]) && !empty($_POST["id"])) { require_once "login.php"; $stmt = $conn->prepare("DELETE FROM teamlid WHERE lidnummer = ?"); $stmt->bind_param("i", $param_id); $param_id = $_POST["id"]; $stmt->execute(); if ($stmt) { header("location: teamsTabel.php"); exit(); } else { echo "Oeps, er is iets verkeerds gegaan. Probeer het later nog een keer."; } mysqli_close($conn); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Gegevens inzien</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css"> <style type="text/css"> .wrapper { width: 500px; margin: 0 auto; } </style> </head> <body> <div class="wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div class="page-header"> <h1>Gegevens verwijderen</h1> </div> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <div class="alert alert-danger fade in"> <input type="hidden" name="id" value="<?php echo trim($_POST["id"]); ?>" /> <p>Weet je zeker dat je deze gegevens wilt verwijderen?</p><br> <p> <input type="submit" name="submitDeleteBtn" value="Ja" class="btn btn-danger"> <a href="teamsTabel.php" class="btn btn-default">Nee</a> </p> </div> </form> </div> </div> </div> </div> </body> </html> Another PHP script I tried didn't work either: <?php if (isset($_POST["id"]) && !empty($_POST["id"])) { require_once "login.php"; // DELETE query om op basis van lid.lidnummer en postcode.postcode de tabellen te legen. $sql = "DELETE lid, postcode FROM lid INNER JOIN postcode WHERE lid.postcode = postcode.postcode AND lid.lidnummer = ?"; if ($stmt = mysqli_prepare($conn, $sql)) { mysqli_stmt_bind_param($stmt, "s", $param_id); $param_id = trim($_POST["id"]); if (mysqli_stmt_execute($stmt)) { header("location: read.php"); exit(); } else { echo "Oeps, er is iets verkeerds gegaan. Probeer het later nog een keer."; } } mysqli_stmt_close($stmt); mysqli_close($conn); } else { if (empty(trim($_GET["id"]))) { header("location: error.php"); exit(); } } ?> But they're both not doing what I want: deleting the rows in the "teamlid" table where the id matches the column "lidnummer". I'm not getting any errors. When using the delete statement directly in MySQL using a hardcoded "lidnummer" it works. But it's not using the lidnummer here to delete the corresponding columns in the table. I can't get my head around it. Do you guys have any ideas? Thanks!
  8. You're right about that. But to get the input from the dropdown, what value should I assign to those variables? (the reason I assigned empty strings to those variables is because I copied them from my other application page where I used an input form to get the data. I thought if I use that as a basis and work on from there it would help, but alas).
  9. Hello there! I've been banging my head on this for a while and I just can't seem to get it to work properly. I have a dropdown menu which selects information from table1 using a select statement (this table is called 'lid'). It selects the firstname, lastname and member id from this table and shows it in the dropdown menu. I'm glad I got that part working but the hard thing is inserting the data that the user selects into another table. So when you select the id member from this dropdown menu it only inserts a blank row into table2 (which is called 'teamlid'). Can you guys help me? How can I insert the id member into my table2? What am I doing wrong here? Thanks a million! This is my first post so if I'm doing anything wrong, let me know and I'll fix it asap! My code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Boast & Drive</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css"> <style type="text/css"> .wrapper{ width: 650px; margin: 0 auto; } .page-header h2{ margin-top: 0; } table tr td:last-child a{ margin-right: 15px; } </style> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div class="page-header clearfix"> <h2 class="pull-left">Teamleden</h2> <div class="btn-toolbar"> <a href="read.php" class="btn btn-primary btn-lg pull-right">Terug</a> </div> </div> <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL); //Verbinding maken met de database require_once "login.php"; $sql = "SELECT tl.teamnaam, tl.tl_ID, tl.lidnummer, l.voornaam, l.achternaam FROM teamlid tl JOIN lid l ON tl.lidnummer = l.lidnummer ORDER BY tl.teamnaam;"; if($result = mysqli_query($conn, $sql)) { if(mysqli_num_rows($result) > 0) { echo "<table class='table table-bordered table-striped'>"; echo "<thead>"; echo "<tr>"; echo "<th>Teamnaam</th>"; echo "<th>Tl_ID</th>"; echo "<th>Lidnummer</th>"; echo "<th>Voornaam</th>"; echo "<th>Achternaam</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; while($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['teamnaam'] . "</td>"; echo "<td>" . $row['tl_ID'] . "</td>"; echo "<td>" . $row['lidnummer'] . "</td>"; echo "<td>" . $row['voornaam'] . "</td>"; echo "<td>" . $row['achternaam'] . "</td>"; echo "<td>"; echo "<a href='update.php?id=". $row['lidnummer'] ."' title='Gegevens wijzigen' data- toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>"; echo "<a href='delete.php?id=". $row['lidnummer'] ."' title='Lid verwijderen' data- toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>"; echo "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; mysqli_free_result($result); } else{ echo "<p class='lead'><em>Er zijn geen gegevens om weer te geven.</em></p>"; } } else{ echo "De volgende fout is gevonden: " . mysqli_error($conn); } ?> <form name="dropdown" method="post"> <div class="page-header clearfix"> <h2 class="pull-left">Teamlid toevoegen</h2> </div> <p>Selecteer hieronder met behulp van het dropdown menu een lid welke je aan bovenstaand team wilt toevoegen</p> <div class="container-fluid"> <div class="row"> <?php // Variabelen aanmaken en tonen met lege waardes $teamnaam = $lidnummer = ''; // Code voor dropdown. Selecteert voornaam, achternaam en lidnummer van tabel lid) $sql = "SELECT voornaam, achternaam, lidnummer FROM lid ORDER BY achternaam"; $result = mysqli_query($conn, $sql); echo "<select id='teamLid' name='teamLid'>"; echo "<option>--Selecteer Lid--</option>"; while ($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['lid'] . "'>" . $row['voornaam'] . " " . $row['achternaam'] . " " . $row['lidnummer'] . "</option>"; } echo "</select>"; if (isset($_POST["id"]) && !empty($_POST["id"])) { $id = $_POST["teamLid"]; $stmt = $conn->prepare("INSERT INTO teamlid (teamnaam, lidnummer) VALUES (?,?)"); $stmt->bind_param('si', $param_teamnaam, $param_lidnummer); $param_teamnaam = $teamnaam; $param_lidnummer = $lidnummer; $stmt->execute(); } // Verbinding sluiten mysqli_close($conn); ?> <div> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" name="submit" class="btn btn-primary" value="Toevoegen"> </div> </div> </div> </form> </div> </div> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.