Jump to content

Recommended Posts

ok, it is working properly, but how do I put in my drop down menu for the event, there could be a total of 8 events to choose from.  You made it a text box, how do you make it a drop down menu.......I could try it myself, but with all the things you added, I don't really know whats what and I don't wanna mess it up.

To display a dropdown menu change

        <?php
            for($i = 1; $i <= 8; $i++):

                $titleNum = "title$i";
                $titleText = $$titleNum;

                if(!empty($titleText)): ?>

            <input type="text" name="<?php echo $titleNum; ?>" value="<?php echo $titleText; ?>" />

        <?php
                endif;
            endfor; ?>

To

        <select name="title">
        <?php
            for($i = 1; $i <= 8; $i++):

                $title= ${"title$i"}; ?>

            <option value="<?php echo $$title; ?>"><?php echo $$title; ?>" />

        <?php
            endfor; ?>
       </select>

However now that you have the drop down menu. We now have a problem.

A drop menu can only have one name and submits the chosen values. It doesn't submit the unchosen ones, so how are you supposed to add the chosen title into the corresponding title field?

 

You're better of getting rid of the fields title1-8 in your events table and have a single field (call it event_title) for storing the chosen event title. If you go this route then change

            for($i = 1; $i <= 8; $i++)
                ${"title$i"} = isset($_POST["title$i"]) ? $_POST["title$i"] : '';

            $query_values[] = "('$title1', '$title2', '$title3', '$title4', '$title5', '$title6', '$title7', '$title8', '$userid', '$name','$eventid', '$event', '$email', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', '$id')";
        }

        $query = "insert into Events (\n\ttitle1, title2, title3, title4, title5, title6, title7, title8, userid, name,  eventid, event, email, \n\t" .

To

            for($i = 1; $i <= 8; $i++)
                $event_title = $_POST["title"]);

            $query_values[] = "('$event_title', '$userid', '$name','$eventid', '$event', '$email', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', '$id')";
        }

        $query = "insert into Events (\n\event_title, userid, name,  eventid, event, email, \n\t" .

 

 

also I don't need the query to echo any more, could you take that off, I don't know what is what for I havn't ever seen this type of code

Either comment out or remove this line

        echo "Generated query: <pre>$query</pre>";

I only added that for debug purposes. So I could see how the query was being generated.

 

I havn't ever seen this type of code

The query inserts multiple records at once. Rather than inserting a new record one by one.

ok, I see what you are saying, but a person can be registered for more than one event.  I should actually change the query to a replace into though for this way to work with the drop down menu.  that way it will update every time I were to register someone for like title1 then for title2 so that way each person can be registered for multiple events if available.  how do I do this so that it updates multiples instead of one at a time.

Then replace code

        <?php
            for($i = 1; $i <= 8; $i++):

                $titleNum = "title$i";
                $titleText = $$titleNum;

                if(!empty($titleText)): ?>

            <input type="text" name="<?php echo $titleNum; ?>" value="<?php echo $titleText; ?>" />

        <?php
                endif;
            endfor; ?>

With your old code

<?php
    if (!empty($title1)) { echo  "<select name=\"title1\" id=\"title1\">
       <option value=\"$title1\">$title1</option>";}
    if (!empty($title2)) { echo  "<select name=\"title2\" id=\"title1\">
       <option value=\"$title2\">$title2</option>";}
    if (!empty($title3)) { echo  "<select name=\"title3\" id=\"title1\">
       <option value=\"$title3\">$title3</option>";}
    if (!empty($title4)) { echo  "<select name=\"title4\" id=\"title1\">
       <option value=\"$title4\">$title4</option>";}
    if (!empty($title5)) { echo  "<select name=\"title5\" id=\"title1\">
       <option value=\"$title5\">$title5</option>";}
    if (!empty($title6)) { echo  "<select name=\"title6\" id=\"title6\">
       <option value=\"$title6\">$title6</option>";}
    if (!empty($title7)) { echo  "<select name=\"title7\" id=\"title1\">
       <option value=\"$title7\">$title7</option>";}
    if (!empty($title8)) { echo  "<select name=\"title8\" id=\"title1\">
       <option value=\"$title8\">$title8</option>";}
?>
</select>

Which just displays separate menus for each event title that isn't empty

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.