WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode Exec PHP
[resolved] Error messages - how to interpret (10 posts)

  1. Jeff M.
    Member
    Posted 2 years ago #

    Hello, again!

    Take a look at the following post:

    PDATA Test

    Any clue as to why I am getting error messages? The shortcode appears to be executing properly.

    http://wordpress.org/extend/plugins/shortcode-exec-php/

  2. Marcel Bokhorst
    Member
    Plugin Author

    Posted 2 years ago #

    Since you didn't post the code, I can only guess. 'mysql_real_escape_string' needs an open database connection to work (which is indeed a little counter-intuitive).

  3. Jeff M.
    Member
    Posted 2 years ago #

    Here is the code:

    extract(shortcode_atts(array('arg' => 'default'), $atts));
    
    $playerID = $arg;
    
    $dbbosfan = mysql_connect ("localhost", USERNAME, PASSWORD);
    if (!$dbbosfan){
    	die ('I cannot connect to the database because: ' . mysql_error());
    }
    
    mysql_select_db ("bosfan_redsox",$dbbosfan);
    
    $query = "SELECT * FROM playerdata pd WHERE pd.playerID = '$playerID'";
    $result = mysql_query($query,$dbbosfan) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    $p_name = $row['fullname'];
    $p_byy = $row['byy'];
    $p_bmm = $row['bmm2'];
    $p_bdd = $row['bdd'];
    $p_posID = $row['posID'];
    $p_pos = $row['pos'];
    
    $p_legend = FALSE;
    if ($row['legend'] == TRUE){
    	$p_legend = TRUE;
    }
    
    $p_soxhof = FALSE;
    if ($row['soxhof'] == TRUE){
    	$p_soxhof = TRUE;
    	$p_soxhofyear = $row['soxhofyear'];
    }
    
    $p_bbhof = FALSE;
    if ($row['bbhof'] == TRUE){
    	$p_bbhof = TRUE;
    	$p_bbhofyear = $row['bbhofyear'];
    }
    
    mysql_close($dbbosfan);
    
    print "  <p><strong>Date of Birth</strong>: ".$p_bdd." ".$p_bmm." ".$p_byy."<br/>\n";
    
    if ($p_soxhof = TRUE){
      print "    <strong>Elected to Red Sox Hall of Fame</strong>: ".$p_soxhofyear."<br/>\n";
    }
    
    if ($p_bbhof = TRUE){
      print "    <strong>Elected to Baseball Hall of Fame</strong>: ".$p_bbhofyear."<br/>\n";
    }
    
    print "  </p>\n\n";
  4. Marcel Bokhorst
    Member
    Plugin Author

    Posted 2 years ago #

    Warning: mysql_real_escape_string(): 14 is not a valid MySQL-Link resource in /home/bosfan/public_html/onebostonfan/wp-includes/wp-db.php on line 787

    Warning: mysql_error(): 14 is not a valid MySQL-Link resource in /home/bosfan/public_html/onebostonfan/wp-includes/wp-db.php on line 1098

    It seems these errors are not related to the shortcode, look at the file names.

  5. Jeff M.
    Member
    Posted 2 years ago #

    Resolved it... apparently, it did not like the use of the mysql_close() fuction.

  6. Jeff M.
    Member
    Posted 2 years ago #

    So now when I remove the mysql_close() function, some of the other WP-specific widgets do not function. For example, on this page:

    PDATA Test Page

    The script runs, but then the sidebar widgets for the Categories and Tags show no output.

    My guess is that the opening of the SQL database separate from the QP SQL database is the culprit.

  7. Marcel Bokhorst
    Member
    Plugin Author

    Posted 2 years ago #

    Is the database you are using in the script the WordPress database? If so, you should use the WordPress functions to access it.

  8. Jeff M.
    Member
    Posted 2 years ago #

    No, it's a separate database.

  9. Marcel Bokhorst
    Member
    Plugin Author

    Posted 2 years ago #

    Maybe you should re-select the WordPress database at the end of the script (mysql_select_db).

  10. Jeff M.
    Member
    Posted 2 years ago #

    Bingo! Thanks again, Marcel.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic