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 8591717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:35:21+00:00 2026-06-11T23:35:21+00:00

I feel like I’m making a rookie error here somewhere but can’t figure out

  • 0

I feel like I’m making a rookie error here somewhere but can’t figure out what’s going wrong. I am using PHP and mySQL. I have an array $users that stores a current user’s information. The array is storing the customer id (cid, its an integer). So I’m trying to pull information that is only tagged to a specific customer. My code is:

try
{
    $sql = 'SELECT id, title, image_url FROM shelf WHERE cid = $user['cid']'; 
    $result = $pdo->query($sql);
}

I feel like I have similar code in other parts of my program that are working so this seems like I may be doing something wrong in terms of syntax. If I replace $user['cid'] in the request with a hard-coded number like 22, the statement works fine. However, I need to pull the integer from $user. I’m getting a T_STRING error on the SELECT statement line. I have also tried to add an additional set of single quotes around $user['cid'] but that’s not working either (i.e. $user['cid'])

Thanks for your help.

Twine

  • 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-11T23:35:21+00:00Added an answer on June 11, 2026 at 11:35 pm

    You’re using PDO, so you should be using place-holders, too:

    $stmt = $pdo->prepare('SELECT id, title, image_url FROM shelf WHERE cid=:cid');
    $stmt->bindParam(':cid', $user['cid']);
    $stmt->execute();
    

    This ensures your data is escaped correctly and handles conversion to the appropriate database format where required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this should be simple, but can't figure it out: What's the
I feel like I've only ever seen this here on SO, but I can't
I feel like I'm missing something obvious, but I can't work out why my
I feel like I'm missing something very obvious here, but I can't get a
I feel like this question is basic enough to be out there somewhere, but
I feel like I'm using Ruby the wrong way here: I want to generate
I feel like a fool, couldn't figure out how to change case using jQuery.
Feel like I'm going a bit nutty here. I have a detail view with
I feel like I am just missing a simple property, but can you set
I feel like I am missing something very simple here, but this is the

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.