3raser Posted April 5, 2011 Share Posted April 5, 2011 I get a "No database selected" error whenever I submit information on my register.php page, which is: <?php include_once('includes/config.php'); include_once('functions.php'); $return_content = AccountRelated(null, null, 3); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style/style.css" /> <title><?php echo $title; ?></title> </head> <body> <div class="logo"><a href="index.php"><img src="style/images/logo.png" border="0"></a></div> <center> <div class="background"> <div class="container"> <?php echo $return_content; ?> </div> </div> </center> </body> </html> But after I click submit, I get the "No database selected" error, but using WAMP, I include config.php which holds the following details: <?php $title = "NovaUpload - File Uploader"; mysql_connect("localhost", "", ""); mysql_select_db("data"); ?> And if functions.php is required, here: <?php function AccountRelated($username, $password, $query_type) { if($query_type == 1) { $set_query = mysql_query("SELECT COUNT(d.username), u.date, u.username FROM uploads d, users u WHERE d.username = '$username' AND u.username = '$username' LIMIT 1") or die(mysql_error()); //user must not exist if(mysql_num_rows($set_query) == 0) { $content_return = 'Sorry, no information was found'; } else { $grab = mysql_fetch_assoc($set_query); //login information if($grab['COUNT(d.username)'] > 0) { $welcome_return = "You have uploaded ". $grab['COUNT(d.username)'] ." files. You've registered on ". $grab['u.date'] ."!"; } else { $welcome_return = "You have uploaded 0 files. You've registered on ".$grab['date'] . "!"; } } } elseif($query_type == 2) { $set_query = mysql_query("SELECT title,views,downloads,description,username,date FROM uploads LIMIT 20"); if(mysql_num_rows($set_query) == 0) { $content_return = "Sorry, there are currently no files uploaded to view."; } else { //display all files while($row = mysql_fetch_assoc($set_query) == 0) { echo $row['title']."<br/>"; } } } elseif($query_type == 3) { $username = mysql_real_escape_string($_POST['username']); $password = sha1(sha1(md5($_POST['password']))); if(!$username || !$password) { $return_content = "All fields are required! <table><form action='register.php' method='POST'> <tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr> <tr><td>Password</td><td><input type='text' name='password' maxlength='30'</td></tr> <tr><td><input type='submit' value='Register'></td></tr> </form></table>"; } else { $set_query = mysql_query("SELECT username FROM users WHERE username = '$username' LIMIT 1"); if(mysql_num_rows($set_query) == 0) { $return_content = "You have successfully registered the account ". $username ." with the password ". $_POST['password'] ."!"; mysql_query("INSERT INTO users VALUES (null, '$username', '$password', 0, 0, '". date("M-d-Y") ."', '". $_SERVER['REMOTE_ADDR'] ."')") or die(mysql_error()); } else { $return_content = "An account with this username already exists."; } } return $return_content; } else { //nothing to process } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/ Share on other sites More sharing options...
Zane Posted April 5, 2011 Share Posted April 5, 2011 I get a "No database selected" error I hate to be Cap. Obvious, but this would mean you haven't selected a database. Database are selected, in PHP, using the function mysql_select_db you don't have to assign it to a variable either... once you call the function, the database is used until you call that function again or you close the connection. Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197027 Share on other sites More sharing options...
3raser Posted April 5, 2011 Author Share Posted April 5, 2011 I get a "No database selected" error I hate to be Cap. Obvious, but this would mean you haven't selected a database. Database are selected, in PHP, using the function mysql_select_db you don't have to assign it to a variable either... once you call the function, the database is used until you call that function again or you close the connection. Did you read my whole post? <.< Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197047 Share on other sites More sharing options...
Zane Posted April 5, 2011 Share Posted April 5, 2011 Weird, can't believe I missed that. Try putting mysql_select_db("data"); inside your AccountRelated function. preferably at the beginning of it. Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197052 Share on other sites More sharing options...
gizmola Posted April 5, 2011 Share Posted April 5, 2011 You aren't checking for return values, so either the mysql_connect or the mysql_select_db could have failed. Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197054 Share on other sites More sharing options...
Zane Posted April 5, 2011 Share Posted April 5, 2011 You aren't checking for return values, so either the mysql_connect or the mysql_select_db could have failed. Yeah, most likely your connection is OK because you're getting a No Database Selected error, I'll bet you just mispelled your db. Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197055 Share on other sites More sharing options...
blacknight Posted April 5, 2011 Share Posted April 5, 2011 try using this format with wamp $mysql = $wowdb->connect($db_host, $db_user, $db_passwd, $db_name); $db = mysql_select_db($db_name); if(!$mysql) die("Can´t connect to MySql!<br>".mysql_error()." ".mysql_errno()); if(!$db) die("Can´t connect to MySql Database!<br>".mysql_error()." ".mysql_errno()); Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197058 Share on other sites More sharing options...
3raser Posted April 5, 2011 Author Share Posted April 5, 2011 No, my database is not spelled wrong. Also, I tried this: <?php $title = "NovaUpload - File Uploader"; $mysql = $wowdb->connect("localhost", "", "", "data"); $db = mysql_select_db("data"); if(!$mysql) die("Can´t connect to MySql!<br>".mysql_error()." ".mysql_errno()); if(!$db) die("Can´t connect to MySql Database!<br>".mysql_error()." ".mysql_errno()) ?> But I get a blank page for some reason. o.O Is it possible when functions.php is loaded, config.php is out of range? But I tried adding the config.php contents inside functions.php, and it still didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197059 Share on other sites More sharing options...
3raser Posted April 5, 2011 Author Share Posted April 5, 2011 Fixed/Solved. Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197061 Share on other sites More sharing options...
gizmola Posted April 5, 2011 Share Posted April 5, 2011 Pebkac? Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197063 Share on other sites More sharing options...
Pikachu2000 Posted April 5, 2011 Share Posted April 5, 2011 Probably . . . Quote Link to comment https://forums.phpfreaks.com/topic/232726-mysql-error-first-time-at-wamp/#findComment-1197175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.