Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:11:17+00:00 2026-06-01T03:11:17+00:00

I have a MySQL table called Users. The rows have 4 fields and look

  • 0

I have a MySQL table called Users. The rows have 4 fields and look like:

  INT(10) |  serialized php array    |    CHAR(24) |  CHAR(254)
   id     |   profile                | name        |  email
   1      | ..ybl4JFtmhQEQVwQOXjo... | TestName    |  testmail@test.com
   2      | ..hd+F2yZVYPlxmyalrQo... | NameTest    |  mailtest@test.com

I have a name of a user (TestName) and want to get the unique user id (1).
Why does following code not work?

function dataBase() {
    $dataBase = @new MySQLi("localhost", "name", "password", "databasename");
    if (mysqli_connect_errno()) {
        safeExit("Failed to establish connection to MySQL database, error: ".mysqli_connect_error(), 'msgError');
    } else {
        return $dataBase;
    }
}

// connect to database
$db = dataBase();

$sql = 'SELECT
            id
        FROM
            Users
        WHERE
            name = ?
        LIMIT
            1';
$stmt = $db->prepare($sql);
if (!$stmt) {
    safeExit($db->error, 'msgError');
}

$name = 'TestName';

$stmt->bind_param('s', $name);
if (!$stmt->execute()) {
    safeExit($stmt->error, 'msgError');
}
    $stmt->bind_result($uid);
    $stmt->close();
echo $uid;

This code outputs a zer0. I can exclude syntax errors. Something must be wrong with the query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:11:18+00:00Added an answer on June 1, 2026 at 3:11 am

    You have not fetched the row from $stmt. Look over the examples on the mysqli::bind_result() documentation to see how this is usually done with a call to $stmt->fetch() either singly when expecting one row, or in a while loop.

    $stmt->bind_param('s', $name);
    if (!$stmt->execute()) {
        safeExit($stmt->error, 'msgError');
    }
    
    $stmt->bind_result($uid);
    
    // Fetch the row so it populates the result variable
    $stmt->fetch();
    echo $uid;
    
    $stmt->close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table called users with the following fields: username - password
I have this mysql table called comments which looks like this: commentID parentID type
I am using MYSQL and PHP. I have a table called item. Two of
I know the basics of PHP and MySQL. If I have a table called
I have a table called Users it contain some fields such as Id, ParentId,
I have a MySql table called reviews which stores a lot of product reviews,
I have a legacy MySQL table called lnk_lists_addresses with columns list_id and address_id .
Hi I have a field in mySql table called jobnumber which auto increments with
I have a date and time column in my mysql table called start_date and
I have a MySQL db and inside it a table called ProductMaster with 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.