错误mysql没有选择数据库

时间:2016-10-16 23:33:39

标签: php mysql

<?php
ob_start();
session_start();
ini_set('error_reporting', E_ALL|E_STRICT);
ini_set('display_errors', 1);
require ('openid.php');

function logoutbutton() {
    //echo "<form action=\"steamauth/logout.php\" method=\"post\"><input value=\"Logout\" type=\"submit\" /></form>"; //logout button
    echo "<a href=\"steamauth/logout.php\" class=\"button7\">Logout</a>";
}

function steamlogin() {
    try {
        require("settings.php");
        $openid = new LightOpenID($steamauth['domainname']);

        $button['small'] = "small";
        $button['large_no'] = "large_noborder";
        $button['large'] = "large_border";
        $button = $button[$steamauth['buttonstyle']];

        if(!$openid->mode) {
            if(isset($_GET['login'])) {
                $openid->identity = 'http://steamcommunity.com/openid';
                header('Location: ' . $openid->authUrl());
            }
        }

        elseif($openid->mode == 'cancel') {
            echo 'User has canceled authentication!';
        } else {
            if($openid->validate()) { 
                $id = $openid->identity;
                $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
                preg_match($ptn, $id, $matches);
                var_dump($steamauth['loginpage']);
                //session_start();
                $_SESSION['steamid'] = $matches[1]; 
                include_once("set.php");
                $query = mysql_query("SELECT * FROM users WHERE steamid='".$_SESSION['steamid']."'");
                if (mysql_num_rows($query) == 0) {
                    if(isset($_SESSION['ref'])) {
                        mysql_query("INSERT INTO users (steamid, referal) VALUES ('".$_SESSION['steamid']."',".$_SESSION['ref'].")") or die("MySQL ERROR: ".mysql_error());
                    } else {
                        mysql_query("INSERT INTO users (steamid) VALUES ('".$_SESSION['steamid']."')") or die("MySQL ERROR: ".mysql_error());
                    }

                    $query2 = mysql_query("SELECT * FROM users");
                    $id = mysql_num_rows($query2);

                    if($id % 100 == 0) {
                        mysql_query("UPDATE users SET bonus=(bonus+1) WHERE steamid='".$_SESSION["steamid"]."'");
                        mysql_query("UPDATE users SET money=(money+50) WHERE steamid='".$_SESSION["steamid"]."'");
                    }
                }
                include_once("userInfo.php");

                mysql_query("UPDATE users SET nickname='".$steamprofile['personaname']."', avatar='".$steamprofile['avatarfull']."' WHERE steamid='".$_SESSION["steamid"]."'");
                $user = mysql_fetch_array($query, MYSQL_ASSOC);

                $query = mysql_query("SELECT * FROM users WHERE steamid='".$_SESSION['steamid']."'");
                $user = mysql_fetch_array($query, MYSQL_ASSOC);
                if(isset($_SESSION['ref']) && $user['referal'] == "" && (int)$user['id'] != (int)$_SESSION['ref']) {
                    $result = mysql_query("SELECT * FROM users WHERE id=".(int)$_SESSION['ref']);
                    $row = mysql_fetch_array($result, MYSQL_ASSOC);
                    mysql_query("UPDATE users SET referal='".$row['steamid']."' WHERE steamid='".$_SESSION['steamid']."'");
                    mysql_query("UPDATE users SET money=(money+10) WHERE steamid='".$_SESSION['steamid']."'");
                }
                if (isset($steamauth['loginpage'])) {
                    header('Location: '.$steamauth['loginpage']);
                }
            } else {
                echo "User is not logged in.\n";
            }

        }
    } catch(ErrorException $e) {
        echo $e->getMessage();
    }
}

?>

的settings.php:

<?php
$steamauth['apikey'] = "i entered my apikey "; //  Steam WebAPI-Key http://steamcommunity.com/dev/apikey
$steamauth['domainname'] = "mytests.esy.es"; // s
$steamauth['buttonstyle'] = "large"; // Style of the login button [small|large_no|large] 
$steamauth['logoutpage'] = "index.php"; // Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = "index.php"; // Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!

// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!</div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = "mysql.hostinger.co.uk";}
if ($steamauth['buttonstyle'] != "small" and $steamauth['buttonstyle'] != "large") {$steamauth['buttonstyle'] = "large_no";}
?>

set.php

<?
$sitename = "mytests.esy.es";
$link2 = mysql_connect("mysql.hostinger.co.uk", "my user base entered", "my password entered");
$db_selected = mysql_select_db('db_case', $link2);
mysql_query("SET NAMES utf8");

function fetchinfo($rowname,$tablename,$finder,$findervalue) {
    if($finder == "1") $result = mysql_query("SELECT $rowname FROM $tablename");
    else $result = mysql_query("SELECT $rowname FROM $tablename WHERE `$finder`='$findervalue'");
    $row = mysql_fetch_assoc($result);
    return $row[$rowname];
}
?>

数据库用户名,密码等正确但我有错误

当我进入页面时:

  欢迎客人!请登录

     

string(2)“./”   警告:mysql_num_rows()期望参数1是资源,布尔值在第46行的/home/u704631182/public_html/steamauth/steamauth.php中给出

     

MySQL错误:未选择数据库

0 个答案:

没有答案