• okay so total newb on the plugin front here, so please be nice ??

    I am writing a simple plugin for my website. I have a basketball website and want to have a scoreboard on the homepage. However, I want to have all the data on the scoreboard easily changed from inside wordpress.

    I created the plugin and got that working okay. I created the table in mysql and got that working okay. The table is called “scoreboard” and I have 2 rows with data in it for now. However, here is my problem.

    How do i query that table to 1) show the current values on my admin page and 2) update those values as necessary from the admin page? I have been searching all night and I cannot get it to work right.

    Thanks for any help!

Viewing 4 replies - 16 through 19 (of 19 total)
  • Thread Starter maestro42

    (@maestro42)

    okay. Thank you very much for your help!

    <?php if( $_POST['team1'] != ''){
    
    $team1 = $_POST['team1'];
    $id = $_POST['id'];
    
    $table_name = $wpdb->prefix . "scoreboard";
    $quer = "UPDATE " . $table_name . " SET team1 = '" . $team1 . "' WHERE id = '" . $id . "'";
    
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($quer);
    }
    ?>
    
    <?php
    
    	global $wpdb;
    	$table_name = $wpdb->prefix . "scoreboard";
    	$result = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE id=1");
    
       foreach ($result as $results) {
          $id = $results->id;
          $team1 = $results->team1;
          $team1_score = $results->team1_score;
          $team2 = $results->team2;
          $team2_score = $results->team2_score;
        }
    ?>
          <form name='update_team1' id='update_team1' method='POST' action='<?= "https://"
             . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] ?>'>
    
             <input type='hidden' name='id' value="<?php echo $id; ?>" /><input name="team1" value="<?php echo $team1; ?>" type="text" /><input type="submit" value="Update Widget Footer" />
          </form>

    The above code does not update the value in the table when submitted.

    If I change the 7th line from:

    $quer = "UPDATE " . $table_name . " SET team1 = '" . $team1 . "' WHERE id = '" . $id . "'";

    to:

    $quer = "UPDATE wpSite_scoreboard SET team1 = '" . $team1 . "' WHERE id = '" . $id . "'";

    it works okay. Can’t figure out why!

    Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    Email me. michael (AT) semperfiwebdesign (DOT) com
    It’s easier than going back and forth like this.

    Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    Nevermind, I looked at it again. You messed up your string. Take a closer look at your ‘s and “s.

    Thread Starter maestro42

    (@maestro42)

    okay. thanks a lot.

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘newb with mysql query question’ is closed to new replies.