0

I am uploading a csv to my database, in the csv there are 2 fields Firstname and Lastname. On my database I want to combine them into one Name column. However I am not sure exactly how to do so

        $compname = $data[4] . ',' . $data[5];
    $import="INSERT into gaa_ccinvoices_contacts(id,name,contact,email,contact_note) values('$data[0]','". $compname ."','". $compname ."','$data[6]','". $compname ."')";
2
  • 4
    DON'T do this... never denormalize your data. and as written, you're vulnerable to sql injection attacks. Commented Jun 29, 2015 at 20:31
  • What you've written should work. Are you getting an error when you try it? Commented Jun 29, 2015 at 20:40

1 Answer 1

1

If you really wanto to insert only a composed field in the database use string concatenation :

 $dataComposed = $data[0] . ',' . $data[1];
 $import="INSERT into table(name) values('" . $dataComposed ."')";
Sign up to request clarification or add additional context in comments.

3 Comments

I get what you are trying to do here, can't seem to avoid the syntax error now.
I've tried that as well, updating code above with exactly what I have
Strange, It's just a syntax error but everything seemed to upload correctly. Thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.