1

I have a problem with my web page.

$server = mysql_connect($server_host, $server_user, $server_pass, true); 
mysql_select_db($server_db, $server);

$web = mysql_connect($foorum_host, $foorum_user, $foorum_pass); 
mysql_select_db($foorum_db, $web);

This is my connection part.

        if(isset($_POST['logisisse'])) {

        $user = mysql_real_escape_string($_POST['user']);
        $pass = mysql_real_escape_string($_POST['pass']);

        $osqlq = "SELECT * FROM mybb_users WHERE username='$user'";
        $asqlq = "SELECT username FROM mybb_users WHERE username='$user'";

        $osql = mysql_fetch_array(mysql_query($osqlq, $web));
        $asql = mysql_num_rows(mysql_query($asqlq, $web));

        $salt = $osql['salt'];

        if(empty($user) || empty($pass)) {
            echo '<div class="alert alert-danger">Täida kõik väljad.</div>';
        }
        else if($asql < 1) { // pole kasutajat
            echo'<div class="alert alert-danger">Sellist kasutajat ei eksisteeri.</div>';
        }
        else if($osql['pass'] != $hashedPassword) { // vale parool
            echo '<div class="alert alert-danger">Sisestasid vale parooli.</div>';
        }
    }
    echo '
                <aside class="widget widget_search">
                  <h3 class="widget-title">Logi sisse</h3>
                  <form role="login" method="post" class="validate-form" />
                    <div>
                      <label class="screen-reader-text" for="s">Logi sisse:</label>
                      <input type="text" value="" id="user" name="user" placeholder="Foorumi kasutajanimi" class="required" />
                      <input type="password" value="" id="pass" name="pass" placeholder="Parool" class="required" />
                      <br /><br />
                      <button id="logisisse" name="logisisse" value="Logi sisse" />
                    </div>
                  </form>
                </aside>
    ';

This is where the problem is, it gives me a error like this.

Warning: mysql_query() expects parameter 2 to be resource, null given in /data03/virt47609/domeenid/www.example.com/htdocs/ucp/inc/mysql.php on line 32

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /data03/virt47609/domeenid/www.example.com/htdocs/ucp/inc/mysql.php on line 32

Warning: mysql_query() expects parameter 2 to be resource, null given in /data03/virt47609/domeenid/www.example.com/htdocs/ucp/inc/mysql.php on line 33

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /data03/virt47609/domeenid/www.example.com/htdocs/ucp/inc/mysql.php on line 33

"var_dump($server)" gives me "resource(2) of type (mysql link)" but just before the $osql it gives me "NULL"

"var_dump($web)" gives me "resource(3) of type (mysql link)", same goes to here.

Lines 32 and 33 are

    $osql = mysql_fetch_array(mysql_query($osqlq, $web));
    $asql = mysql_num_rows(mysql_query($asqlq, $web));

Also my MySQL connections are working perfectly.

I've have been trying to search the problem from google but it didn't help, maybe you guys can help me.

martin
  • 50
  • 7

2 Answers2

0

Add error handling like this:

<?php
$link = mysql_connect($server_host, $server_user, $server_pass, true); 
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

?>

And then do the same for second connection. Also mysql_* functions are deprecated.

Just for sake of testing try this:

$server = mysql_connect($server_host, $server_user, $server_pass); 
mysql_select_db($server_db, $server);

$web = mysql_connect($foorum_host, $foorum_user, $foorum_pass, true); 
mysql_select_db($foorum_db, $web);
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
  • My MySQL connections are working perfectly, these don't give any errors. – martin Mar 29 '15 at 12:41
  • Ok, but it's always good practice to do error handling...Try to var_dump($web) and var_dump($server) right before the query... – Whirlwind Mar 29 '15 at 12:41
0

I found the problem. My web page login script was an function, I copied the function to where the login script should be and it works like a charm.

martin
  • 50
  • 7