doudouwd2017 2014-06-14 08:50
浏览 33
已采纳

PHP - MySql:(String)将斜杠放在2个数字之间

I've problem in my code, I use these lines for example:

$numb1 = 12;
$numb2 = 6;
$folder = (string)$numb1."/".$numb2;
echo ($folder); // => 12/6
$sql="insert into test (folder) values (".$folder.");   
// Here the value of folder is "2" !!!
// Structure of the colume folder : varchar(50) utf8_general_ci 

I went insert in this column "folder" the string output "12/6", but every time in database I get the division of $numb1 / $numb2, in this case I get "2";.

  • 写回答

2条回答 默认 最新

  • douba1498 2014-06-14 08:56
    关注

    You should really be using mysqli. It's much more secure.

    You're missing quotes around your string. SQL needs quotes to identify it as a string. Otherwise it uses as a number.

    Where you say

    insert into ... values(12/6)
    

    It should be

    Insert into ... Values '12/6')
    

    Try:

    "INSERT INTO test (folder)
    VALUES ('".$folder."')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题