如何在PHP中连接用户定义的变量并将结果插入MySQL表

如何在PHP中连接用户定义的变量并将结果插入MySQL表

问题描述:

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.

我正在尝试将三个变量连接成一个变量,并将结果插入到MYSQL表中。 p>

到目前为止,这是我的代码: p>

  $ title = $ _GET ['title'];  
 $ color = $ _GET ['color'];  
 $ shoe_id = $ _GET ['shoe_id']; 
 
 $ order_title = $ title +'('+ $ color +'|'+ $ shoe_id'); 
 
 $ sql =“INSERT INTO order  (order_title_1)
VALUES('$ order_title')“; 
 $ result = mysql_query($ sql); 
 
结果:$ title($ color | $ shoe_id)
i.e。  Ara Ladies Reggio Lazer剪裁裤子(白色| 51179-05G)|  12200 
  code>  pre> 
 
 

目前存储在数据库中的结果为零。 我认为这是因为我错误地使用了'+'运算符,但是,我不确定我应该使用什么来连接变量。 p>

如何正确连接变量需要做什么? p>

感谢。 p> div>

Correct way is

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

In PHP concate operator is . not +

+ is an arithmetic operator in PHP