WordPress.org

Ready to get started?Download WordPress

Forums

Dropdown Form pulling from MySQL DB (1 post)

  1. J031
    Member
    Posted 3 years ago #

    Hello all.

    I'm having issues with my Plugin. It's supposed to display a dropdown menu that is populated with song titles from a MySQL database. When you then select a song title and hit "submit" it should reload the page and display the corresponding song's lyrics (also pulled from the MySQL database)

    But it doesn't work. All that happens is that the page refreshes and resets the drop down to the first entry.

    I am really at the end of my rope trying to figure out the problem, so I thought I would see if any of you have any ideas.

    Please feel free to look at my code, copy and try it out yourself, or whatever you need to do.

    (The project is not online. Just localhost for now. Sorry!)

    <?php
    /*
    Plugin Name: Lyrics Dropdown Demo
    Plugin URI:
    Description:
    Author: Joel
    Version: 1
    Author URI:
    */
    add_filter('the_content','lyricsplug');
    
    function my_plugin_activate()
    {
    //Creates the necessary tables
    global $createTablesQuery;
    $createTablesQuery =
    "CREATE TABLE IF NOT EXISTS <code>wp_lyric2</code> (
      <code>songid</code> int(10) NOT NULL AUTO_INCREMENT,
      <code>songname</code> varchar(50) COLLATE latin1_general_ci NOT NULL,
      <code>lyrics</code> text COLLATE latin1_general_ci NOT NULL,
      PRIMARY KEY (<code>songid</code>)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ";
    
    global $createTablesResult;
    $createTablesResult = mysql_query($createTablesQuery)
    or die(mysql_error());
    
    //Populates the necessary tables
    global $popTablesQuery;
    $popTablesQuery =
    "INSERT INTO <code>wp_lyric2</code> (<code>songid</code>, <code>songname</code>, <code>lyrics</code>) VALUES
    (1, 'SONG ONE', 'LYRICS GO HERE SONG 1'),
    (2, 'SONG TWO', 'LYRICS GO HERE SONG 2');";
    
    global $popTablesResult;
    $popTablesResult = mysql_query($popTablesQuery)
    or die(mysql_error());
    
    }
    
    function my_plugin_deactivate()
    {
    }
    if ( !function_exists('lyricsplug') )
    {
    function lyricsplug()
    {
    if (isset($_POST['songname']))
    {
    global $songidresult;
    $songidresult = $_POST['songname'];
    global $lyricquery;
    $lyricquery =
    "SELECT
    	lyrics
    FROM
    	wp_lyric2
    WHERE
    	songname = '{$songidresult}'";
    global $needResultsData2;
    $needResultsData2 = mysql_query($lyricquery)
    or die(mysql_error());
    while($result15 = mysql_fetch_array($needResultsData2))
    {
    Print $result15[0];
    }
    }
    
    else
    {
    
    global $lyric_list;
    $lyric_list =
    "SELECT
    songname
    FROM
    wp_lyric2;
    ";
    
    global $lyric_list_result;
    $lyric_list_result = mysql_query($lyric_list)
    or die(mysql_error());
    		?>
    		<form method="POST" id="lyrics" action="">
    		<?php
    
    				print "<select name=" . $_POST['songname'] . ">\r\n";
    
    				while ($row = mysql_fetch_array($lyric_list_result)){
    					$songidresult = $row['songname'];
    
    					print "<option value=$songidresult>$songidresult\r\n";
    				}
    				print "</select>\r\n";
    				print "</p>\n";
    				?>
    			<input type="submit">
    			</form>
    		<?php } } }
     ?>
    <?php
    register_activation_hook(__File__,"my_plugin_activate");
    register_deactivation_hook(__FILE__,"my_plugin_deactivate");
    ?>'

Topic Closed

This topic has been closed to new replies.

About this Topic