Jump to content

Skippy1957

New Members
  • Posts

    3
  • Joined

  • Last visited

Skippy1957's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Ben thanks for this fine code! After changing the code, mathching my table for our choir, and adding fields i got the following messages: Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables in /xxxxx/records.php on line 205 Warning: mysqli_stmt::execute() [mysqli-stmt.execute]: (HY000/2031): No data supplied for parameters in prepared statement in /home/xxxxxxxxx/records.php on line 206 Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxxx/records.php:205) in /home/xxxxxxx/records.php on line 216 I searched and searched but i cant't find the fault. Could you help me out? greetings Jos ============code koorrecord.php also attached as pagina.php================== <?php /* Allows the user to both create new records and edit existing records */ // connect to the database include("koorconnect-db.php"); // creates the new/edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($naam = '', $mp3naam ='', $links ='', $linka ='', $linkt='', $linkb='', $yt1='', $yt2='', $bladm='', $opm='', $error = '', $id = '') { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <link rel='stylesheet' href='style2.css' type='text/css'> <head> <title> <?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>"; } ?> <form action="" method="post"> <div> <?php if ($id != '') { ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <p>ID: <?php echo $id; ?></p> <?php } ?> <strong>Naam: *</strong> <input type="text" name="naam" value="<?php echo $naam; ?>"/><br/> <strong>Mp3 naam: *</strong> <input type="text" name="mp3naam" value="<?php echo $mp3naam; ?>"/> <strong>Sopraan: *</strong> <input type="text" name="links" value="<?php echo $links; ?>"/> <strong>Alt: *</strong> <input type="text" name="linka" value="<?php echo $linka; ?>"/> <strong>Tenor: *</strong> <input type="text" name="linkt" value="<?php echo $linkt; ?>"/> <strong>Bas: *</strong> <input type="text" name="linkb" value="<?php echo $linkb; ?>"/> <strong>Youtube 1: *</strong> <input type="text" name="yt1" value="<?php echo $yt1; ?>"/> <strong>Youtube 2: *</strong> <input type="text" name="yt2" value="<?php echo $yt2; ?>"/> <strong>Bladm: *</strong> <input type="text" name="bladm" value="<?php echo $bladm; ?>"/> <strong>Opmerking: *</strong> <input type="text" name="opm" value="<?php echo $opm; ?>"/> <p>* required</p> <input type="submit" name="submit" value="Submit" /> </div> </form> </body> </html> <?php } /* EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['id'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['id'])) { // get variables from the URL/form $id = $_POST['id']; $naam = htmlentities($_POST['naam'], ENT_QUOTES); $mp3naam = htmlentities($_POST['mp3naam'], ENT_QUOTES); $links = htmlentities($_POST['links'], ENT_QUOTES); $linka = htmlentities($_POST['linka'], ENT_QUOTES); $linkt = htmlentities($_POST['linkt'], ENT_QUOTES); $linkb = htmlentities($_POST['linkb'], ENT_QUOTES); $yt1 = htmlentities($_POST['yt1'], ENT_QUOTES); $yt2 = htmlentities($_POST['yt2'], ENT_QUOTES); $bladm = htmlentities($_POST['bladm'], ENT_QUOTES); $opm= htmlentities($_POST['opm'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($naam == '' || $mp3naam == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($naam, $mp3naam, $links, $linka, $linkt, $linkb, $yt1, $yt2, $bladm, $opm , $error, $id); } else { // if everything is fine, update the record in the database if ($stmt = $mysqli->prepare("UPDATE players SET naam = ?, mp3naam = ?, links = ?, linka = ?, linkt = ?, linkb = ?, yt1 = ?, yt2 = ?, bladm = ?, opm = ? WHERE id=?")) { $stmt->bind_param("ssi", $naam, $mp3naam, $links, $linka, $linkt, $linkb, $yt1, $yt2, $bladm, $opm, $id); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: xxxxx/koor"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['id']) && $_GET['id'] > 0) { // get 'id' from URL $id = $_GET['id']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT * FROM nummers WHERE id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); /*$stmt->bind_result($id, $naam, $mp3naam);*/ $stmt->bind_result($id, $naam, $mp3naam, $links, $linka, $linkt, $linkb, $yt1, $yt2, $bladm, $opm); $stmt->fetch(); // show the form renderForm($naam, $mp3naam, $links, $linka, $linkt, $linkb, $yt1, $yt2, $bladm, $opm, NULL, $id); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location: view.php"); } } } /* NEW RECORD */ // if the 'id' variable is not set in the URL, we must be creating a new record else { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // get the form data $naam = htmlentities($_POST['naam'], ENT_QUOTES); $mp3naam = htmlentities($_POST['mp3naam'], ENT_QUOTES); $links = htmlentities($_POST['links'], ENT_QUOTES); $linka = htmlentities($_POST['linka'], ENT_QUOTES); $linkt = htmlentities($_POST['linkt'], ENT_QUOTES); $linkb = htmlentities($_POST['linkb'], ENT_QUOTES); $yt1 = htmlentities($_POST['yt1'], ENT_QUOTES); $yt2 = htmlentities($_POST['yt2'], ENT_QUOTES); $bladm = htmlentities($_POST['bladm'], ENT_QUOTES); $opm= htmlentities($_POST['opm'], ENT_QUOTES); // check that firstname and lastname are both not empty if ($naam == '' || $mp3naam == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Vul de verplichte velden in!'; renderForm($naam, $mp3naam, $error); } else { // insert the new record into the database if ($stmt = $mysqli->prepare("INSERT nummers (naam, mp3naam, links, linka, linkt, linkb, yt1, yt2, bladm, opm) VALUES (?, ?, ?,?,?,?,?,?,?,? )")) { $stmt->bind_param("ss", $naam, $mp3naam, $links, $linka, $linkt, $linkb, $yt1, $yt2, $bladm, $opm); $stmt->execute(); $stmt->close(); } // show an error if the query has an error else { echo "ERROR: Kan geen SQL statement maken."; } // redirec the user header("Location:xxxxx/koor"); } } // if the form hasn't been submitted yet, show the form else { renderForm(); } } // close the mysqli connection $mysqli->close(); ?> pagina.php
×
×
  • Create New...