【问题标题】:insert 'print rand' into DB [closed]将'print rand'插入数据库[关闭]
【发布时间】:2014-02-25 06:49:05
【问题描述】:

我正在尝试将一个随机的 8 位数字插入数据库

这是我用来生成随机数的代码

'insert 'print rand' into DB '

这是我当前的插入代码

     mysql_select_db("cl49-XXX", $con); $sql="
   INSERT INTO member (title,firstname,lastname,daytimetel,mob,work,email,
   address1,address2,towncity,postcode,country,password,phrase,businesstype,businesscontact,regno,regcountry,pos,created) 

  VALUES('$title','$firstname','$lastname','$daytimetel','$mob','$work','$email',
   '$address1','$address2','$towncity','$postcode','$country','$password','$phrase','$businesstype','$businesscontact','$regno','$regcountry','$pos','$created')";

如何插入?

【问题讨论】:

  • 你用的是什么数据库?
  • 你的 PHP 代码在哪里
  • @Sundar 我已经添加了我的 php 代码
  • 我无法理解你在尝试什么

标签: php mysql database random


【解决方案1】:

要获取号码,请使用mt_rand()

$number = mt_rand( 10000000, 99999999);

要将其存储在数据库中,请将其插入PDO

$pdo = new PDO( '', $db_username, $db_password); // read the docs for this
$stmt = $pdo->prepare('INSERT INTO mytable (column_name) VALUES ( ? )');
$stmt->execute( array( $number));

这是您的一般查询

   INSERT INTO your_table (your_column_name) VALUES ( '$number' )

【讨论】:

    猜你喜欢
    • 2012-08-21
    • 2013-07-02
    • 2013-03-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多