Hi, so im trying to insert data but i get:

Notice: Undefined index: events

html part:

<form method="post" action="seating.php>
    <div class="drop">
        <label>Event : <label/>
        <select name="events" id="dd-events" onchange="getguests(this.value)">
            <option value="" disabled selected >Event</option>
                <?php foreach($retrieve as $r): ?>
                <option value="<?=$r['event_id']?>"><?=$r['event_name']?></option>
                <?php endforeach ?>

    <input type="hidden" name="table_name[]" value='+tablename+'><span class="tableName">'+tablename+'</span>
    <input type="text" name="guestname[]" class="add-name" size="40">


        require "connection.php";
        $name = $_POST['guestname'];
        $table = $_POST['table_name'];
        $event = $_POST['events'];//<- THIS LINE
        $sess = $_SESSION['sess_user_id'];

        $seats = $dbh->prepare("INSERT INTO tables(tuser_id,table_name,event_id,guest_name)

        for($i = 0; $i < count($_POST['guestname']); $i++)
            if(trim($_POST['guestname'][$i]) != '')
                $seats->bindParam(1, $sess);
                $seats->bindParam(2, $table[$i]);
                $seats->bindParam(3, $event);   
                $seats->bindParam(4, $name[$i]);
                    echo "fail!";

Im still a baby at php and all programming so I can't see where I made a mistake. could someone point it out to me please. thank you.

Recommended Answers

All 2 Replies

If no event has been selected from the dropdown, you are in trouble since $_POST['events'] possibly does not exist and you get a notice (the script obviously gets executed anyway). What you have to do is to check for existence and act appropriately:

if(isset($_POST['events'])) {
    $event = $_POST['events'];
} else {
    // do something (get user to provide the data or provide a default value yourself...)

You might use this technique for all fields that might be empty but are mandatory. or even better do a client side check first using javascript.

it had to do with my html. had to resturctur it.

Be a part of the DaniWeb community

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