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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:51:26+00:00 2026-05-28T03:51:26+00:00

Need your help. I need to update the array data in the mysql table.

  • 0

Need your help.

I need to update the array data in the mysql table. my problem is that there are some array values which dont have “photo” coloum (check 4th field in the array) because of that my query is failing with error “Column count doesn’t match value count at row 1”
below is what im trying.

    $dept = $job->user();
$sql = array(); 
    foreach( $dept as $row ) {
       $sql[] = '('.$row['dob'].', "'.($row['name']).'", "'.($row['role']).'"
 "'.$row['email'].'", "'.($row['photo']).'" )';
    }
    mysql_query('INSERT INTO cast (dob, name, role, email, photo) VALUES '.implode(',', $sql)) or die(mysql_error());

Array Data

array
  0 => 
    array
      'dob' => string '01121978'
      'name' => string 'Ram Avtar'
      'role' => string 'Inspector'
      'email' => string 'ramavtar@gmail.com'
      'photo' => string ' '
  1 => 
    array
      'dob' => string '15021978'
      'name' => string 'Suresh Babu'
      'role' => string 'Constable'
      'email' => string 'ssbh1@mail.yahoo.com'
      'photo' => string ' ' 
  2 => 
    array
      'dob' => string '11111965'
      'name' => string 'Dean'
      'role' => string 'Inspector'
      'email' => string 'ddepth@live.in'
      'photo' => string ' '
  3 => 
    array
      'dob' => string '10061979'
      'name' => string 'Rohit Shette'
      'role' => string 'Sergeant'
      'email' => string ' '
      'photo' => string ' '
  4 => 
    array
      'dob' => string '15081979'
      'name' => string 'Ian'
      'role' => string 'warden'
      'email' => string ' '

table structure

 CREATE TABLE user(
      id INT(5) NOT NULL AUTO_INCREMENT,
      dob TEXT NOT NULL,
      name TEXT NOT NULL,
      role TEXT DEFAULT NULL,
      email TEXT DEFAULT NULL,
      photo TEXT DEFAULT NULL
    )
    ENGINE = INNODB
    CHARACTER SET latin1
    COLLATE latin1_swedish_ci;
  • 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-28T03:51:26+00:00Added an answer on May 28, 2026 at 3:51 am

    The actual problem is that you missed a comma.

    Change:

    echo $sql[] = '('.$row['dob'].', "'.($row['name']).'", "'.($row['role']).'"
      "'.$row['email'].'", "'.($row['photo']).'" )';
    

    To:

    $sql[] = "('{$row['dob']}', '{$row['name']}', '{$row['role']}',
     '{$row['email']}', '{$row['photo']}')";                  // ^^^  Here is the missing comma
    

    The missing values will not cause a problem, they will just cause an empty string to be inserted, because the string is quoted. However, you may wish to test to make sure the key exists in the array array before you try to use it, to avoid any nasty E_NOTICEs.

    Also, make sure you properly escape your data before you use it in a query – you don’t want a visit from Bobby Tables…

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

Sidebar

Related Questions

I have a problem with my UPDATE functions and I need your help. I
I've some questions .. and I really need your help. I have an application.
ive being trying to cope with this problem but still. I need your help.
We have a security problem here and we really need your help and inputs.
Need your help with authenticating an active directory user ID against LDAP. My problem
I need your help, For example I have a decimal type variable and I
I need your help to define a special case in XML schema: A sequence
I really need your help in my issue very quickly and it's too close
I really need your help for this. I am relatively new to programming and
I'm completely stuck and need your help... I've created a webservice stub with jaxb

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.