Andreycon Posted July 17, 2020 Share Posted July 17, 2020 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!!! Quote Link to comment Share on other sites More sharing options...
gw1500se Posted July 17, 2020 Share Posted July 17, 2020 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. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 17, 2020 Share Posted July 17, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
gw1500se Posted July 18, 2020 Share Posted July 18, 2020 Sorry, I was thinking UPDATE not INSERT. 1 Quote Link to comment Share on other sites More sharing options...
StevenOliver Posted July 20, 2020 Share Posted July 20, 2020 On 7/17/2020 at 12:19 PM, gw1500se said: This should get you started. I bookmarked this, too. I know nothing about PDO, I'm intent on learning it! Thank you!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.