PHP MySQL用千位分隔符插入整数 [英] PHP MySQL insert integer with thousand seperator

查看:74
本文介绍了PHP MySQL用千位分隔符插入整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP代码,它将带有千位分隔符的整数插入数据库。但是,它不能保存整个整数。
Exp:10,234,234<-在数据库中将仅显示为10。
5,434<-显示为5

I have a PHP code that will insert integer numbers with thousand separator into the database. However, it could not save the whole integer.. Exp: 10,234,234 <-- Will only appear as 10 in the database. 5,434 <- Appear as 5

我的代码:

 <html>
<body>

<?php
session_start();
$date =  $_SESSION['storeDate'];
$a = $_SESSION['storeA'];
$l = $_SESSION['storeL'];
$p = $_SESSION['storeP'];
$m = $_SESSION['storeM'];

$con = mysql_connect("localhost","root","password");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

    mysql_select_db("productno", $con);

    $sql="INSERT INTO records (Date, A, L, P, M)
    VALUES
    ('$date', '$a', '$l', '$p', '$m')"; 

    if (!mysql_query($sql,$con))
    {
        echo ("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('Save Failed.')
        window.location.href='main.php'
        </SCRIPT>");
    }else{
       echo ("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('Record Added.')
        window.location.href='main.php'
        </SCRIPT>");
 }

?>

</body>
</html>

如何修改它以便存储整数-> 10,234,234
谢谢

How do I modify it so that it will store the whole number -> 10,234,234 Thanks

推荐答案

如果列中的数据类型为 INT ,则否

If the data type in your column is INT, then no matter what you try, it will always be truncated.

如果您确实希望插入该图形,或者可以这样做,则可以这样做:

If you really want that figure to be inserted, alternatively, you could do it like this:

$number = '10,234,234';
$number = filter_var($number, FILTER_SANITIZE_NUMBER_INT); // becomes 10234234
// insert code the rest of the way

侧面注:方式,请尝试迁移到改进的扩展名 mysqli _ * PDO ,并使用准备好的语句。

Sidenote: By the way, try to migrate to the improved extension which is mysqli_* or PDO and utilize prepared statements.

这篇关于PHP MySQL用千位分隔符插入整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆