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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:04:13+00:00 2026-06-11T01:04:13+00:00

I am trying to implode some variables and insert them into a MySql database,

  • 0

I am trying to implode some variables and insert them into a MySql database, but for some reason it is not working. I have been trying for hours and I”m just not sure what I’m doing wrong.
If you can help it would be much appreciated.

$AddressString = "address1,address2,address3,address5,postcode";

$AddressSplit = explode( ",", $AddressString );    //split the address string
$StringLength = count( $AddressSplit ) - 1;
$s = 0;      //trim any white spaces from the address string
while ( $s < count( $AddressSplit ) ) {
  $AddressSplit[$s] = trim( $AddressSplit[$s] );
  $s++;
}

//Create the Values to insert into DB
$MysqlValues = implode( "','", $AddressSplit );
$MysqlValues = "'$MysqlValues'";
$NumberVals = count( $AddressSplit );

$t = 1;
while ( $t < $NumberVals ) {
  $ad[$i] = "add$i";
  $t++;
}
$TableNames = implode( ", ", $ad );

mysql_query( "INSERT INTO pstc_add_main (" . $TableNames . ",add10,date)
                                VALUES (" . $MysqlValues . ",'$cdate')" );
}
  • 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-06-11T01:04:14+00:00Added an answer on June 11, 2026 at 1:04 am

    Because you start making the field names 1 based, your are one field short!
    In the end you must end with a equal number of fields and values.

    Try this:

    $t = 0;
    while ( $t < $NumberVals ) {
      $ad[$i] = "add$i";
      $t++;
    }
    

    Or, if you do not want the first field to be “add”, change it like this:

    $t = 1;
    while ( $t <= $NumberVals ) {
      $ad[$i] = "add$i";
      $t++;
    }
    

    Of course, it would have been a easy test to do:

    $sql = "INSERT INTO pstc_add_main (" . $TableNames . ",add10,date)
                               VALUES (" . $MysqlValues . ",'$cdate')";
    var_dump($sql);
    mysql_query($sql);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make this information insert into my table in mysql database with
I'm trying to use fgetCsv but for some reason it is only reading the
I'm trying to convert some MYSQL querys to MYSQLI, but I'm having an issue,
I have a variable holding values separated by a comma (Implode), and I'm trying
I am trying to integrate some third party tracking code into one of my
Im trying to list all added products from my session['cart'] and implode them, I
I've been trying to use a PHP integer array for a MySQL query that
I'm trying to switch some hard-coded queries to use parameterized inputs, but I've run
I've been trying to get a php/mysqli simple search up and running, but i
I am trying to use jQuery's fancy autocomplete function but I have a problem

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.