简体   繁体   English

MySQL从一个表插入到另一个表

[英]MySQL Insert from one table to another

I am trying to select a random address from one table and add it at one of the columns on the other table but it keeps saying "no database selected" 我正在尝试从一个表中选择一个随机地址,并将其添加到另一张表的一列中,但是它一直在说“未选择数据库”

if ($_SESSION[address] == "")
{
    $db = @mysql_select_db($db_bitcoins,$connection)
        or die(mysql_error());
    $sql = "SELECT Count(*) FROM address";
    $result = @mysql_query($sql, $connection) or die(mysql_error());
    $rnum = mysql_num_rows($result);
    $rrr=rand(1,rnum);
    $sql = "SELECT * FROM address WHERE id = '$rrr'";
    $result = @mysql_query($sql, $connection) or die(mysql_error());
    while ($sql = mysql_fetch_object($result)) {
        $_SESSION[address]  = $sql -> ads;
        $db = @mysql_select_db($db_name,$connection)
                        or die(mysql_error());
        $sql = "UPDATE $table_name SET bitaddress = $_SESSION[address] WHERE username = '$user' and password = password('$pass')";
        $result = @mysql_query($sql, $connection) or die(mysql_error());
    }
}

Thanks in advance! 提前致谢!

检查是否正确指定了数据库名称(SID),端口和主机IP,并且数据库是否可以访问(如果不在PC中)。

EDIT:I found out $db_bitcoins wasn't set, thanks for the help everyone! 编辑:我发现未设置$ db_bitcoins,感谢大家的帮助! I get another exception now "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" this time 我现在收到另一个异常"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM