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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:00:05+00:00 2026-05-25T12:00:05+00:00

So I have two arrays, $gDatabaseKeyNames (list of column names) and $gDatabaseKeyValues (a list

  • 0

So I have two arrays, $gDatabaseKeyNames (list of column names) and $gDatabaseKeyValues (a list of variable names containing values from a script). The variable names are generated dynamically so I keep track of them for an insert.

Rather than listing all of the columns and value variables, I tried this

$cols = implode(", ", array_values($gDatabaseKeyNames));
$vals = implode(", ", array_values($gDatabaseKeyValues));

$query = "INSERT INTO pings (survey_id, $cols) VALUES ('$surveyID', $vals)";                              
mysql_query ($query) or die(mysql_error());

But none of my actual values show up in the database (they are inserted as 0s – all my columns are numeric).

If I echo $query, I see this, which is the correct formatting:

INSERT INTO pings (survey_id, latitude, longitude, pingTimestamp) VALUES ('15', '$Dlatitude', '$Dlongitude', FROM_UNIXTIME('$DtimeStamp'))

However, if I change $query to

$query = INSERT INTO pings (survey_id, latitude, longitude, pingTimestamp) VALUES ('$surveyID', '$Dlatitude', '$Dlongitude', FROM_UNIXTIME('$DtimeStamp'));

It works perfectly!

Why isn’t PHP interpreting the variables in the implode? How can I fix this?

  • 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-25T12:00:05+00:00Added an answer on May 25, 2026 at 12:00 pm

    I suspect that $cols has the literal value '$Dlatitude', '$Dlongitude', etc.... PHP does not “double-interpolate” strings. It’ll replace $cols with its values, but will NOT replace $Dlatitude with that variable’s value. In other words, you’re literally inserting some strings-that-look-like-PHP-variable-names into your numeric fields.

    What is in the $gDatabaseKeyValues/Names arrays?

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

Sidebar

Related Questions

I have two arrays containing different keys and values. However, some keys store strings
I have two arrays with anywhere from 1 to 5 set values. I want
I have two arrays with time values in them in this format. 00:00:00 which
I have two arrays of values like X,Y,Z and 1,2 There is a table
I have two arrays consisting of a list emails which I need to send
I have two arrays <?php $x=array('store1'=>'A','store2'=>'B' ,...); ?> and <script type='text/javascript'> var x={srote1: [12,13],store2:[20,23]
I have two arrays values and keys both of the same length. I want
I have two arrays. The first array contains some values while the second array
I have two arrays of values that I would like to combine - but
I have two arrays containing the same elements, but in different orders, and I

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.