skip to Main Content

i have a little problem.

i have a contact-form and want to update my database with a crud.

My Contact-Form:

        <!-- UPDATE -->

        <div class="page-wrapper bg-gra-01 p-t-180 p-b-100 font-poppins">
        <div class="container">
        <?php
                if(isset($_GET['edit'])):
                    $result = $crud->getMember($_GET['edit']);
                ?>
                <hr />
                <div class="row mt-5">
                <h3> UPDATE </h3>
                <form method="post" action="formprocess.php" class="col-12" enctype="multipart/form-data">
                    <div class="form-group">
                        <input type="text" class="form-control" name="vorname" value="<?= $result['vorname']; ?>">
                    </div>
                    <div class="form-group">
                        <label>Foto</label>
                        <input type="file" class="form-control" name="Foto">
                    </div>
                    <div class="form-group">
                        <input type="text" name="birthday" value="<?= $result['birthday']; ?>">
                    </div>
                    <div class="form-group">
                        <h5> Geschlecht </h5>
                        <select name="Geschlecht">
                            <option value=""> </option>
                            <option value=" Männlich" <?php if($result['Geschlecht'] == 'Männlich'){ ?> selected <?php } ?>> Männlich </option>
                            <option value=" Weiblich" <?php if($result['Geschlecht'] == 'Weiblich'){ ?> selected <?php } ?>> Weiblich </option>
                            <option value="Divers"      <?php if($result['Geschlecht'] == 'Divers'){ ?> selected <?php } ?>> Divers </option>
                        </select>
                    </div>
                    <div class="input-group">
                            <input class="input--style-3" type="email" placeholder="[email protected]" name="email" value="<?= $result['email'];?>">
                        </div>
                        <div class="input-group">
                            <input class="input--style-3" type="text" placeholder="01575 2234455" name="phone"  value="<?= $result['phone'];?>">
                        </div>
                    <p> <input type="hidden" name="ID" value="<?= $result['ID']; ?>">
                    <p> <input type="submit" class="btn btn-outline-Success" name="update" Value="Update"> </p>
                </form>
                </div>
                <?php
                 endif;
                ?>

My formprocess:

 if(isset($_POST['update'])) {
        if(isset($_POST['vorname']) && !empty($_POST['vorname']) &&
           isset($_FILES['Foto'])      && !empty($_FILES['Foto'])      &&
           isset($_POST['Geschlecht'])  && !empty($_POST['Geschlecht'])  &&
           isset($_POST['birthday'])    && !empty($_POST['birthday'])    &&
           isset($_POST['phone'])  && !empty($_POST['phone'])  &&
           isset($_POST['email'])  && !empty($_POST['email'])  &&
           isset ($_POST['ID'])  && !empty($_POST['ID'])
        ){
            $vorname = $_POST['vorname'];
            $pfad = "upload/";
            $filename = $_FILES['Foto'] ['tmp_name'];
            $name = $pfad . time() . "-" . $_FILES['Foto'] ['name'];
            $Geschlecht = $_POST['Geschlecht'];
            $birthday = $_POST ['birthday'];
            $phone = $_POST ['phone'];
            $email = $_POST['email'];
            $ID = $_POST ['ID'];

            if(move_uploaded_file($filename,$name)){


           if($crud->updateMember($ID, $vorname, $name, $Geschlecht, $birthday, $phone, $email)) {
               $_SESSION['msg-class'] = "success";
               $_SESSION['msg'] = "Update war erfolgreich!";

               header('location: Admin.php');
           } else{
            $_SESSION['msg-class'] = "danger";
            $_SESSION['msg'] = "Es ist ein Fehler aufgetreten!";

            header('location: Admin.php');
            }
            }
        }

    }

My crud.php:


        public function updateMember($ID, $vorname, $Foto, $Geschlecht, $birthday, $phone, $email) {
            $stmt = $this->conn->prepare("UPDATE testing SET vorname = :vorname, Foto = :Foto, Geschlecht = :Geschlecht, birthday = :birthday, phone = :phone, email = :email WHERE ID=:ID");
            $erg = $stmt->execute(array(
                ':vorname' => $vorname,
                ':Foto' => $Foto,
                ':Geschlecht'  => $Geschlecht,
                ':birthday' => $birthday,
                ':phone' => $phone,
                ':email:' => $email,
                ':ID' => $ID
            ));

            return $erg;

If i press the Update button i get that error:

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:XampphtdocsdashboardpRAKTITesting 3classescrud.php:51 Stack trace: #0 C:XampphtdocsdashboardpRAKTITesting 3classescrud.php(51): PDOStatement->execute(Array) #1 C:XampphtdocsdashboardpRAKTITesting 3formprocess.php(66): Crud->updateMember(’12’, ‘Boris’, ‘upload/16693640…’, ‘ Weiblich’, ‘0000-00-01’, ‘666’, ‘[email protected]’) #2 {main} thrown in C:XampphtdocsdashboardpRAKTITesting 3classescrud.php on line 51

i don’t know why, can anyone help?

2

Answers


  1. Chosen as BEST ANSWER

    i got the solution... my code was apparently "unsorted". For example, I had the birthday in the 3rd place, but entered it as a 4th in the code


  2. I’m not a PHP specialist, but I think your values and DB columns count mismatch. From the exception, I see that you have an invalid parameter number. You can post the whole file so we can debug it together.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search