Jump to content

How do i retrieve inserted values from mysql database with respect to a user id in php?


Andreycon

Recommended Posts

Am a newbie in php. Since I can't insert values to the database with respect to a user Id or with any other token using WHERE clause.

I.e "INSERT INTO receipts(date) VALUES(example) where id="**....."

If I need to fetch several values of column for a particular user, how do I go about it? Thank you!!!

Link to comment
Share on other sites

4 minutes ago, Andreycon said:

Since I can't insert values to the database with respect to a user Id or with any other token using WHERE clause.

Only true if the column of the where clause does not exist. Unless, of course, you don't have privileges.

This should get you started.

Link to comment
Share on other sites

INSERT queries don't have WHERE clauses. they have a list of columns and corresponding values. you would add the user_id column next to the date column and supply the user id value for that column when the query gets executed. you should not put external, unknown, dynamic values directly into a query. use a prepared query.

here's the insert query documentation definition with the most commonly used elements highlighted -

Quote

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    [(col_name [, col_name] ...)]
    {VALUES | VALUE} (value_list) [, (value_list)] ...
    [ON DUPLICATE KEY UPDATE assignment_list]

the value_list definition -

Quote

value_list:
    value [, value] ...

for a prepared query, the value_list would contain a ? place-holder for each value.

  • Great Answer 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.