0

I am trying to allow users of my website to sign in through steam, when you go to the steam api and sign in you get redirected to a page that displays the error " MySQL ERROR: No database selected" Here is the code im using and the paramater that it expects:

<?php
$sitename = "http://www.jackpot-skins.co.uk/";
$link = mysql_connect("localhost", "USERNAME", "PASSWORD");
$db_selected = mysql_select_db('database', $link);
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];
}
?>

Currently I have them set like so:

  <?php
$sitename = "jackpot-skins.co.uk/";
$link = mysql_connect("localhost", "jackp574_admin", "(my actual password");
$db_selected = mysql_select_db('jackp574_database', $link);
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];
}
?>

for some reason I still get the error, any ideas?

Reform
  • 9
  • 1
    [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Sep 15 '15 at 15:31
  • 1
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 15 '15 at 15:31
  • 1
    Add error checking, such as `or die(mysql_error())` to your queries and connections. Or you can find the issues in your current error logs. – Jay Blanchard Sep 15 '15 at 15:33
  • 1
    you're simply assuming your db calls will never fail. you need `mysql_select_db(...) or die(mysql_error())`, `$result = mysql_query(...) or die(mysql_error())`, etc... – Marc B Sep 15 '15 at 15:37
  • Does this look better? connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?> – Reform Sep 15 '15 at 15:41
  • @Reform That should successfully connect via mysqli. It also supports the databasename as a 4th param, eliminating a need for a select_db call. `$conn = new mysqli($servername, $username, $password, 'jackp574_database');` But you must then proceed to convert the other code to use `mysqli_*()` instead of `mysql_*()` as well. And they aren't drop-in replacements. – Michael Berkowski Sep 15 '15 at 16:06

0 Answers0