0

I'm trying to concatenate three variables into one variable and INSERT the result into an MYSQL table.

Here's my code so far:

$title = $_GET['title']; 
$colour = $_GET['colour']; 
$shoe_id = $_GET['shoe_id'];

$order_title = $title + '(' + $colour + '|' + $shoe_id');

$sql="INSERT INTO orders(order_title_1)
VALUES('$order_title')";
$result=mysql_query($sql);

Result : $title ($colour | $shoe_id)
i.e. Ara Ladies Reggio Lazer Cut Trouser Shoe (White | 51179-05G) | 12200

At the moment the result stored in the database is zero. I presume this is because I'm using the '+' operator incorrectly, however, I'm not sure what I should be using to concatenate the variables.

What do I need to do to concatenate the variables properly?

Thanks.

2
  • 1
    Concatenate operator is . in php Commented Apr 15, 2014 at 8:49
  • Whereas + is used as concatenate operator in javaScript. Commented Apr 15, 2014 at 8:59

1 Answer 1

0

Correct way is

$order_title = $title .'( '.$colour.'|'.$shoe_id.' )';

In PHP concate operator is . not +

+ is an arithmetic operator in PHP

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! - I knew it was the incorrect operator, just wasn't sure of the right one.

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.