MySQL从一个表插入另一个表

时间:2012-04-17 11:31:43

标签: php mysql mysql-error-1064

我正在尝试从一个表中选择一个随机地址并将其添加到另一个表中的一个列上,但它一直说“没有选择数据库”

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());
    }
}

提前致谢!

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

编辑:我发现没有设置$ db_bitcoins,感谢大家的帮助!我现在得到另一个例外"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"