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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:47:02+00:00 2026-06-17T15:47:02+00:00

If I have a table named book Column 1 = current_user , Column 2

  • 0

If I have a table named book

Column 1 = current_user
, Column 2 = page_length
, Column 3 = author
, Column 4 = title

I’d like to select the data from columns 2, 3 and 4 that correspond to the currently logged in user. Is the following correct syntax?

<?
global $user;
$user_id=$user->name;
db_query('SELECT * FROM {book} WHERE current_user=$user_id', $page_length, $author,   $title); ?>
  • 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-17T15:47:04+00:00Added an answer on June 17, 2026 at 3:47 pm

    Some tips:

    1. You need to make sure to use quotation marks around the string that is the SQL statement.
    2. Since the username is a user-supplied string, you should use parameter escaping to prevent SQL injections.
    3. You don’t really need to assign the user name to a separate variable ($user_id) to use it.
    4. You need to retrieve your result from the return value of db_query.

    Fixed code:

    <?php
    global $user;
    $res = db_query("SELECT page_length, author, title FROM {book} WHERE current_user = '%s'", $user->name); 
    $row = db_fetch_array($res);
    // now $row['page_length'], $row['author'] and $row['title'] are filled in with values if the query was successful
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named datas and I'm executing a query like this: SELECT
I have a postgresql database that has this column structure: Author id name Book
Lets say I have table named Place with columns: placeId int not null auto_increment,
I have a table named size here, something like this: size id | size
I have a table named scores with the columns id and score . I
I have a table named with Sales having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i
I have a table with a column that I want to extract out and
I have three tables: author (columns: aut_id, aut_name) book (columns: book_id, book_title) authorbook (linking
I have a table [Book] in a database that has a [AuthorId] and [Description]
I have item_Details table with 3 columns named as itemID, itemName, itemValue. I would

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.