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

  • Home
  • SEARCH
  • 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 7013533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:24:01+00:00 2026-05-27T22:24:01+00:00

If I have mysql table foo with fields a, b, c, d with multiple

  • 0

If I have mysql table foo with fields a, b, c, d with multiple records and a being the primary key. Record 1 has the following data: a = 1, b = true, c = val1a, d = val2a.
If I want to access the data using php, I do:

$result = mysql_query("SELECT * FROM foo WHERE a = '1'");
$rec = mysql_fetch_array($result);

To change b and c, I would do:

mysql_query("INSERT INTO foo (b,c) VALUES (false,'newval') WHERE a = '1'");

Is there a way to write the whole record without listing all the fields (a,b,c,d)?

What I would like to do is write the whole $rec back to table foo:

$rec['b'] = false;
$rec['c'] = 'newval';
mysql_query("INSERT INTO foo $rec");

I know I could do a foreach and build the whole insert, but is there already a php function that does what I am tryng to accomplish?

  • 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-05-27T22:24:02+00:00Added an answer on May 27, 2026 at 10:24 pm

    Simple answer – no. There are a lot of things that should be considered when inserting the values, what their type is, have they been escaped or not, do they need quotes around them or not, etc. So generally all the values cannot be treated the same and just added to a string. It’s better to use an extension like MySQLi, not build the queries by concatenating stings. A simple function can do what you want with a loop as you’ve guessed, but I wouldn’t recommend that.

    Also – you’ve mistaken about something:

    mysql_query("INSERT INTO foo (b,c) VALUES (false,'newval') WHERE a = '1'");
    

    is invalid syntax. You need to use UPDATE to change b and c. You also don’t need the quotes around the id, i.e. WHERE a = '1' should be WHERE a = 1, it’s an integer value.

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

Sidebar

Related Questions

Let's say I have a mysql table, called foo with a foreign key option_id
I have tables foo and bar: create table foo(a int, b varchar(10), primary key
If i have data in my MySQL like this table: data(TEXT) foo (hal) foo
I have a MySQL table (table1) with following fields... id, title, description, detail, category,
I have mysql table that has a column that stores xml as a string.
I have a MySQL table LOGIN_LOG with fields ID, PLAYER, TIMESTAMP and ACTION. ACTION
I have a MySQL table holding lots of records that i want to give
I'm trying to execute this simple command: create table foo (clo int primary key
We have a MySQL table that was altered with ALTER TABLE t COMMENT 'foo'
I have a table called foo with columns like the following: id usedId (id

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.