I want to select the from values from database in WordPress?

Here is my code:

$sql = 'SELECT * FROM ' . $wpdb->base_prefix . 'item WHERE uname = "'. $_POST['login_name'] . '" ';
$result = $wpdb->get_results($sql) or die(mysql_error());
foreach($result as $results) {
    $results->salt;
    $results->password;
  }
echo $sal->$results[0];
echo $pwd->$results[1];

Related posts

Leave a Reply

1 comment

  1. Read the wpdb docs and don’t forget to protect your query:

    global $wpdb;
    $table_name = $wpdb->prefix . "item"; 
    $login_name = sanitize_user( $_POST['login_name'] ); //assuming you're dealing with username
    
    $prepare = $wpdb->prepare( "SELECT * FROM $table_name WHERE uname = %s", $login_name );
    
    $myrows = $wpdb->get_results( $prepare );
    
    //output results
    echo '<pre>' . print_r( $myrows, true ) . '</pre>';