-1
<?php
    $host = "localhost";
    $username = "root";
    $password = "";
    $db = "mineforums";

    $connect = mysqli_connect($host, $username, $password, $db) or die(mysqli_error($connect));
?>

That is my php code to connect to my database. Whenever I try to just connect though it doesnt do anything. The way I have my login-form setup is the action will be to this code and then doesnt do anything and when I return to my index it says database not selected because if you're logged in it says 'Welcome, {username}'

  • 1
    *"because if you're logged in it says 'Welcome, {username}'"* - show the code where that's included in. Your "posted" code seems fine to me. I'm guessing you are probably mixing `mysqli_` with `mysql_` functions; they do not mix together. Show full code, because by the looks of your other question http://stackoverflow.com/q/25519639/ that's what I think you may be doing. – Funk Forty Niner Aug 30 '14 at 22:08

1 Answers1

1

you could split the process

<?PHP
    $host = "localhost";
    $username = "root";
    $password = "";
    $db = "mineforums";

    $connect = mysql_connect($host, $username, $password)OR DIE("Could Not Connect To Server". MySQL_Error());

    if($connect) {
        mysql_select_db($db)OR DIE("Could Not Select Databse". MySQL_Error();
    }
?>
TerryG
  • 309
  • 1
  • 10
  • OP is using `mysqli_`, why `mysql_`? – Funk Forty Niner Aug 30 '14 at 22:07
  • It's just using a deprecated MySQL API. If one doesn't work, why would using this work any better? Far as I'm concerned, OP's connection checks out. Read [`the comment I left`](http://stackoverflow.com/questions/25582280/new-mysqli-connect-cat-find-database/25582333?noredirect=1#comment39965034_25582280) under OP's question. That's what I think is wrong, I'm next to 100% sure of it. That is why I rather ask questions before posting an answer, knowing what I'm dealing with and knowing what the full picture is. – Funk Forty Niner Aug 30 '14 at 22:23
  • 1
    I agree with you. I was just offering an option – TerryG Aug 30 '14 at 22:25
  • 1
    I agree though, it doesn't hurt to try, *cheers*. Let's see what OP has to say. Yet, you stand at being right because OP might be mixing APIs. – Funk Forty Niner Aug 30 '14 at 22:26
  • 1
    You know what Terry, I'm going to +1 your answer, because of what I think may be happening; OP is mixing APIs. Your answer would fall right in with it. – Funk Forty Niner Aug 30 '14 at 22:32