wordpress-logo-stacked-rgb

I am building a WordPress plugin for practice. It’s a modification on the Hello, Dolly plugin that doesn’t really do anything.

As it stands, the Hello, Dolly plugin displays a single, random line from the Louis Armstrong song “Hello, Dolly” at the top of the admin screen.

My version of the plugin will allow you to choose a different song to display. It will also allow you to input your own song with its own lyrics.

Shall we take a look at what we have so far?

Here is a screenshot of the song select form, with sample songs:

When you select and submit a song, the lyrics for that song are displayed at the bottom:


Here’s the code that makes it all work:

<h2>Choose a Song</h2>
    <form action="form.php" method="post">
        <label class="heading">Song Title:</label>
        <br>
    <?php
        while ($row = mysqli_fetch_assoc($results)) : ?>
            <input name="radio" type="radio" value="<?php echo $row['lyrics']; ?>">
                <?php echo $row['title']; ?>
            <br>

        <?php endwhile; ?>
        <br>
            <input name="submit" type="submit" value="Choose Song">
    </form>
                    
<?php
if (isset($_POST['submit'])) {
    if(isset($_POST['radio'])) {
        
        echo "<br><br><span><b>Lyrics</b>: ".$_POST['radio']."</span>";
    } else {
        echo "<br><br><span>Please choose any radio button.</span>";
    }
}
?>


To briefly explain:

The songs are stored in the database.

We’re using the while loop together with the mysqli_fetch_assoc() function to pull it from the database.

It goes through all the info in the table and posts only the Song Title.

It’s then hooked up to the if(isset($_POST[‘radio’])) to display whatever is inside of the input’s “value” section.

Which, in our case, is the lyrics of whatever song we chose.

That’s pretty much everything we have for the plugin so far.

Next up: getting the Add a New Song feature to work.

See you then.