xanawa -3 Junior Poster

Hi, I am trying to call the 'getMembershipDetsPrice()' php function in the html drop down list 'duration'. I tried to follow the W3schools tutorial but when I changed the value the html printed again. When the dropdownlist changed the value the label needs to be filled by the returned value in the 'getMembershipDetsPrice()' php function. Also I tried to use Ajax but I never had experience with it. Could you please help? Maybe a way how I can call the php function and set the label value?

<!DOCTYPE html>
    <?php
    require_once 'DBConnection.php';

    require_once 'DBConnection.php';
    $db = new DBConnection();
    $membershipPrice;
    $membershipDuration;
    $lblmembershipPrice = false;
    $lblmembershipDuration = false;
    $duration = 0;

    function getMembershipDetsPrice($id) {
        $db = new DBConnection();
        // $duration = $_POST['duration'];
        if ($id != -1) {
            $exists = $db->getMemberShipPriceByID($id);

            if ($exists != null && $exists != "") {
                return $exists;
            } else {
                return "";
            }
        }
    }

    if (isset($_POST['submit'])) {
        $title = $_POST['title'];
        $name = $_POST['name'];
        $surname = $_POST['surname'];
        $dateOfBirth = $_POST['dob'];
        $address = $_POST['address'];
        $street = $_POST['street'];
        $locality = $_POST['locality'];
        $postcode = $_POST['postcode'];
        $idcard = $_POST['idcard'];
        $gender = $_POST['gender'];
        $landline = $_POST['landline'];
        $mobile = $_POST['mobile'];
        $email = $_POST['email'];
        $incontact = NULL; // $_POST[''];
        $month = NULL; // $_POST[''];
        $receiptno = NULL; //$_POST[''];
        //
        $duration = $_POST['duration'];
        //$db->addNewMembership($_POST['title'], $_POST['name'], $_POST['surname'], $_POST['address'], $_POST['street'], $_POST['locality'], $_POST['postcode'], $_POST['idcard'], $_POST['gender'], $_POST['landline'], $_POST['mobile'], $_POST['email'], $_POST['incontact'], $_POST['month'], $_POST['posted'], $_POST['receiptno'], $_POST['duration']);

        $exists = $db->checkMemberExists(strtoupper($idcard), strtoupper($name), strtoupper($surname), strtoupper($email));

        if ($exists) {
            $message = "Member Already Exists";
            echo "<script type='text/javascript'>alert('$message');</script>";
        } else {
            $addedSuccess = $db->addNewMember($title, $name, $surname, $address, $street, $locality, $postcode, $idcard, $gender, $landline, $mobile, $email, $incontact, false);
            if ($addedSuccess) {
                //   header('Location: PgMembershipPayment.php?duration=' + $duration);
            } else {
                $message = "Sorry, Member was not added successfully.";
                echo "<script type='text/javascript'>alert('$message');</script>";
            }
    //IF PAYED 
            //INSERT PAYMENT
            //INSERT MEMBERSHIP
        }
    }

    $membershipType = $db->getMemberShipDetailsByID($duration); //$_POST["duration"];
    $membershipCost = 000; // $db->getMemberShipPrice($duration);

    if (isset($_POST['frmMembershipPayment'])) {

        $message = "BOUGHT!";
        echo "<script type='text/javascript'>alert('$message');</script>";
    }
    ?>

    <html>
        <body>
            <form action="PgNewMember.php" method="post">

                    <tr>
                        <td align="right">
                            <label id="lblLandline">Telephone No:</label> 
                        </td>
                        <td>
                            <input type="text" name="landline" id="landline"></input>
                        </td>
                        <td align="right">
                            <label id="lblMobileNo">Mobile No:</label>
                        </td>
                        <td>
                            <input type="text" name="mobile" id="mobile"></input>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <label id="lblEmail">Email:</label>
                        </td>
                        <td>
                            <input type="text" name="email" id="email"></input>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <label id="lblDuration">Membership Duration:</label>  
                            <label id="lblDurationPrice"></label>  
                        </td>
                        <td>
                            <select id="duration" name="duration">
                                <?php
                                $membershipList = $db->getMembershipList();
                                foreach ($membershipList as $q) {
                                    echo $q;
                                }
                                ?>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td><input type="submit" name="submit" value="Submit" /></td>
                    </tr>
                </table>
            </form>
        </body>
    </html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.