skip to Main Content

I have set up my phpmyadmin and everything is working correctly, however I have came across a problem that I never came across I tried to research it but I cant find a solution.

The problem is I have 3 separate input boxes for the user to enter their address like so:
![1]: https://imgur.com/mpM61Ny “Input boxes”.

This is some of the code:

$Line1 = $_POST['FirstLine']  ;
$Line2 = $_POST['City']  ;
$Line3 = $_POST['Postcode']  ;
$Array = array([$Line1] , [$Line2] , [$Line3]);
$Address = implode(', ' , $Array);

$sql = "INSERT INTO CT_expressedInterest (forename, surname ,  email , 
landLineTelNo , mobileTelNo, postalAddress, catID , sendMethod  ) VALUES 
('$forename' ,'$surname' ,'$email' ,'$landLineTelNo' ,'$mobileTelNo' 
,'$Address' ,'$catID' ,'$sendMethod' )";

echo $Address ;

...

I always get a error ‘Array to string conversion’

These are my results in the database:

![1]: https://i.imgur.com/vAfxAeM.png “Results”

2

Answers


  1. Try to replace $Array = array([$Line1], [$Line2], [$Line3]); to $Array = array($Line1, $Line2, $Line3);

    Login or Signup to reply.
  2. $Line1 = $_POST['FirstLine']  ;
    $Line2 = $_POST['City']  ;
    $Line3 = $_POST['Postcode']  ;
    $Array = array($Line1 , $Line2 , $Line3);
    $Address = implode(', ' , $Array);
    
    $sql = "INSERT INTO CT_expressedInterest (forename, surname ,  email , 
    landLineTelNo , mobileTelNo, postalAddress, catID , sendMethod  ) VALUES 
    ('$forename' ,'$surname' ,'$email' ,'$landLineTelNo' ,'$mobileTelNo' 
    ,'$Address' ,'$catID' ,'$sendMethod' )";
    
    echo $Address ;
    

    //Remove the square brackets in the $array

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search