MyBB Community Forums

Full Version: PHP Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Didn't know where else to put this, so yeah...

I'm trying to fetch info from DataBase. What this script is suppose to do is basically
1) get the User's IP address.
2) fetch "lastip" from mybb_users
3) match up user's IP with "lastip"
4) return user info (username, post count, etc)

I'm getting: "No database selected" from my script.

<?php
//Get the IP of the user.
$ip = $_SERVER['REMOTE_ADDR'];

//Database info
$user = "mysql username";
$pass = "password";
$db = "mysqldb";
$host = "host";

//Connect to DB
$cid = mysql_connect($host,$user,$pass);
if (!$cid) {echo("ERROR: " . mysql_error() . "\n");}

//Fetch info
$query  = "SELECT * FROM mybb_users";
$result = mysql_query($query);
//I get "No database selected" right here, on "die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['lastip'];
?>
Well, you've not selected a database Undecided

http://uk3.php.net/mysql-select-db

Or put a database as the fourth parameter in the connect function.
(2010-12-04, 06:08 PM)MattRogowski Wrote: [ -> ]Well, you've not selected a database Undecided

http://uk3.php.net/mysql-select-db

Or put a database as the fourth parameter in the connect function.
New code:
//Connect to DB
$cid = mysql_connect($host,$user,$pass);
if (!$cid) {echo("ERROR: " . mysql_error() . "\n");}
$db_selected = mysql_select_db('mybb_, $cid);
if (!$db_selected) {
    die (mysql_error());
}

//Fetch info
//Fetch info
$query  = "SELECT * FROM mybb_users";
$result = mysql_query($query);
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row;
Access denied for user 'b11_6630766'@'%' to database 'mybb_'
Try this;

//Connect to DB
$cid = mysql_connect($host,$user,$pass);
if (!$cid) {echo("ERROR: " . mysql_error() . "\n");}
$db_selected = mysql_select_db('mybb_, $cid);
if (!$db_selected) {
    die (mysql_error());
}

//Fetch info
$query  = "SELECT * FROM mybb_users";
$result = mysql_query($query);
$row = mysql_fetch_array($result));
echo $row['lastip'];
edit:
current code:
//Connect to DB
$cid = mysql_connect($host,$user,$pass);
if (!$cid) {echo("ERROR: " . mysql_error() . "\n");}
$db_selected = mysql_select_db('mybb_', $cid);
if (!$db_selected) {
    die (mysql_error());
}

//Fetch info
$query  = "SELECT * FROM mybb_users";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['lastip'];
Access denied for user 'myusername' to database 'mybb_'
What, your database is called mybb_?? Undecided That's a table prefix, not a database name...

Why not just include global.php and use the MyBB database functions, it'll make it a lot easier.
As matt said, use the $db functions within MyBB if this is a script for MyBB (which it is) - otherwise you can run into all kinds of issues.
(2010-12-04, 06:44 PM)MattRogowski Wrote: [ -> ]What, your database is called mybb_?? Undecided That's a table prefix, not a database name...

Why not just include global.php and use the MyBB database functions, it'll make it a lot easier.
Is there a MyBB Database Functions wiki?
[Wiki: Database_Methods] (Broken link, head over to docs.mybb.com instead)
(2010-12-04, 06:55 PM)MattRogowski Wrote: [ -> ][Wiki: Database_Methods] (Broken link, head over to docs.mybb.com instead)
Would I be able to include Global.php if the Script is on
subdomain1.myforum.net?
when the forum is located at
myforum.net/forum/
?
Pages: 1 2 3 4