I have setup my WordPress site, customized the Theme as well as a couple plugins, I have also added a custom Table to the WordPress database that will contain user specific information.
I am wanting to call everything in a single row within the table for the specific user.
I have set all my echo statements for the specific column elements of the row however am having difficulty with the initial php to pull the information. No matter what I have tried I keep getting query failed.
Currently I have made it this far however am still having a few issues getting the information to correctly load. any insight would be appreciated. :)
<?php
$servername = "localhost";
$username = "DBusername";
$password = "DBpassword";
$database = "DBname";
// Create connection
$conn = new mysqli($servername, $username, $password);
$db_selected = mysqli_select_db($conn, $database);
$userid = $current_user->user_login;
$sql = "SELECT * FROM 'member-status' WHERE 'Card' = '$userid'";
$result = mysqli_query($conn, $sql);
if ($result) {
list($userid) = mysqli_fetch_array(mysqli_query($result));
} else {
echo "query failed";
}
if (mysqli_connect_errno($conn))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
UPDATE #1
I have began tweaking the code after a bit of further research and decided to clean up the code a bit, I am now not getting the connection errors I was before however I am still not loading the information. any insight would be grateful, here is the revised code.
<?php global $current_user;
wp_get_current_user(); ?>
<?php
$mydb = new wpdb('user','pwrd','db','localhost');
$mydb->show_errors();
$userid = $current_user->user_login;
$query = "SELECT * FROM member_status WHERE CARD = $userid";
$result = $mydb->get_results($query); ?>
<ul>
<li>LAST</li>
<li><?php echo $result["Last"]; ?></li> //need help with this line
</ul>
Thanks in advance for your insight. :)
UPDATE #2 ISSUE RESOLVED
I am happy to announce that I figured out the issue. For anyone else that is wanting to accomplish this task here is the working code that I used.
<?php global $current_user;
wp_get_current_user(); ?>
<?php
// $mydb = new wpdb('username','password','database','localhost');
//$mydb->show_errors();
$userid = $current_user->user_login;
$result = $wpdb->get_results( "SELECT * FROM member_status WHERE CARD = $userid");
// $query = "SELECT * FROM member_status WHERE CARD = $userid";
// $result = $mydb->get_results($query);
?>
<?php foreach ( $result as $query ) {?>
Then to call the individual fields/column data add this code where you want it located
<?php echo $query->ColumnName; ?> //Change ColumnName to the column you want to call from.