douchanxiu5636 2014-04-15 08:47
浏览 28
已采纳

如何在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.

  • 写回答

1条回答 默认 最新

  • doushun9875 2014-04-15 08:48
    关注

    Correct way is

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

    In PHP concate operator is . not +

    + is an arithmetic operator in PHP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料