0

Been designing websites for years - tried to avoid anything MySQL/PHP - deep programming related. Quickly coming to a realization I need to give it a try... UGH. I tried to get my feet wet with MySQL 1 year ago (to the day, apparently... weird?) and was quite unsuccessful. Now, I really need to give it a second try.. I have been searching all over the internet today for assistance (probably troubleshooted 30-40+ different/annoying errors today) - keep coming back to these boards and found a LOT of great info today.. lifesavers, truly.

Ok - now I have a "No Database Selected" issue. I have tried every which way and just stuck.. I searched and searched - I can usually find an answer and troubleshoot my own way around - meaning, if I am asking for help: I probably A) lost my mind after 10+ hours of programming; B) Seriously need help C) All of the above...

Truly sorry if I am not making ANY sense or if this is a total beginners level issue.. I don't want to humiliate myself and hope everyone can be kind to a girl who is really trying! :) Like I said, I have only been attempting MySQL for about 10 hours (today...). Beginning to see double so I figured its worth a shot asking for help (can't hurt... right?)

I am TRYING to create a client login area for my lil' freelance company of mine {plus, great practice... but the end result - I pray it actually is worth it...}. I have tons of files but I think these two different will be the preliminary files to discuss for my issue (let me know if you think I need to include another...)

Clients login @ LOGIN.HTML (simple html username/pwd form...Here is the code I am using for LOGIN.PHP:

<?php session_start();

// Connect to the database
require_once('db.php'); 

// Set username and password variables for this script
$user = mysql_real_escape_string($_POST["username"]);
$pass = mysql_real_escape_string(md5($_POST["password"])); 

// Make sure the username and password match, selecting all the client's
// data from the database if it does. Store the data into $clientdata
$clientdata = mysql_query("SELECT * FROM clients WHERE username='$user' and password='$pass'")
 or die (mysql_error());

// Put the $clientdata query into an array we can work with
$data = mysql_fetch_array($clientdata, MYSQL_ASSOC);

// If the username and password matched, we should have one entry in our
// $clientdata array. If not, we should have 0. So, we can use a simple
// if/else statement
if(mysql_num_rows($clientdata) == 1){
	// Start a new blank session. This will assign the user's server
	// with a session with an idividual ID
	session_start();

	// With our session started, we can assign variables for a logged
	// in user to use until they log out.
	$_SESSION['username'] = $user;
	$_SESSION['email'] = $data['email'];
	$_SESSION['paypal'] = $data['paypal'];

	// Then, redirect them to the profile page
	header('profile.php');
}else{echo "The username and password don't match. Please go back and try again.
            (Or you could redirect them to the login page again.)";}

*** NEXT, I have my "DB.PHP" (database) file (which login is essentially using to connect - if I am once again, using the correct terminology..) [removed my user name and password, obviously.. I don't type them in caps either.. and I have been using my password case sensitive - I don't have an issue logging in as the "test client" that I registered.. it is more of a connection to the database that is causing the issue.

<?php

// Replace these parameters with your own database information.
// I'm running on my own server, so my username is automatically
// root and I have no password. This will be different on a server.
$conn = mysql_connect("SERVERADDRESSHERE.com","DATABASENAMEHERE","TYPEMYPASSWORDHERE");

// mysql_select_db is a predefined function in MySQL
// It let's us call the database, so we can save it
// in our variable $db
$db = mysql_select_db("databasename");

// When a file contains only PHP, it is a good practice
// to not end the file with "?>

After clicking submit on LOGIN.html, I am redirected to LOGIN.PHP with an error "No database selected"... any ideas??

I have come a LONG way today... I really don't want to give up. Dealt with every error message in the programming world today. I don't want to give up again -- especially since I am SURE there is a very simple quick fix and I just can't see it because I am seeing double.

Thank you for your help!!!

4
Contributors
8
Replies
10
Views
6 Years
Discussion Span
Last Post by webdesign4me
0

Works fine on me just make sure your database name is correct and don't use spaces in the name.
Also I don't see why is it that it's such a good practice not to end the php file with "?>" when it's only php... just put it there won't take u any longer.

0

Works fine on me just make sure your database name is correct and don't use spaces in the name.
Also I don't see why is it that it's such a good practice not to end the php file with "?>" when it's only php... just put it there won't take u any longer.

LOL I have no idea what that is about... that's a comment from the script writer of the tutorial I found on creating a portfolio client area.. Guess I'll just have to keep messing around until I get it to work. Probably need to take a break or I may never figure it out. Thanks!

0

If you can provide me access to your database I can check it out. But anyways it should just work lol! There's nothing mysterious about it :), or try to reinstall your mysql server..

0

I think you should take the <?php out. Try it after that. If you take the contents of the db.php and copy and paste them over the require_once line, you will see the lonely <?php just by itself.

When I write php, I start with everything on the page, including classes. Once everything works, I split them up into the requires and includes files. Hope this helps

Edited by tinymark: n/a

0
<?php
 
// Replace these parameters with your own database information.
// I'm running on my own server, so my username is automatically
// root and I have no password. This will be different on a server.
$conn = mysql_connect("SERVERADDRESSHERE.com","DATABASENAMEHERE","TYPEMYPASSWORDHERE");
 
// mysql_select_db is a predefined function in MySQL
// It let's us call the database, so we can save it
// in our variable $db
$db = mysql_select_db("databasename");

Try this,

<?php
 
// Replace these parameters with your own database information.
// I'm running on my own server, so my username is automatically
// root and I have no password. This will be different on a server.
$conn = mysql_connect("localhost","database_username_here","user_password");
 
// mysql_select_db is a predefined function in MySQL
// It let's us call the database, so we can save it
// in our variable $db
[B]$db = mysql_select_db("databasename",$conn);[/B]

NOTE: I wrote localhost as hostname, that can be different also. Check out your what you control panel says.

Hope it helped :)

0

TechySafi...

Thank you so much! It worked! Ahh... all I had to do was ask for help?!? Thank you everyone for your advice - I am such a beginner and put off trying to teach myself MySQL for a long time now. Have to start somewhere, right? It was MUCH easier teaching myself HTML back in 1995/96 (plus things were really simple in terms of coding...) I was 11/12 years old and had a mind like a sponge. Now? Forget it...

Really appreciate your help. Now, onto the next tutorial to teach myself a bit more before my son wakes up..(hope the next step isn't that terrible!)

:)

~ Nicole

0

TechySafi...

Thank you so much! It worked! Ahh... all I had to do was ask for help?!? Thank you everyone for your advice - I am such a beginner and put off trying to teach myself MySQL for a long time now. Have to start somewhere, right? It was MUCH easier teaching myself HTML back in 1995/96 (plus things were really simple in terms of coding...) I was 11/12 years old and had a mind like a sponge. Now? Forget it...

Really appreciate your help. Now, onto the next tutorial to teach myself a bit more before my son wakes up..(hope the next step isn't that terrible!)

:)

~ Nicole

Hahaha man its my pleasure!! it happens to everyone, what do you think? why I know daniweb? :P I take help from here and try to give something back. Nah, its still not that hard, stay focused and keep messing :D
by the way you learnt HTML(web coding)at 12?? HMM!! I'm 17 running...you won :)

0

LOL that is the plan, give something back :)

Yep, I was about 11-12... I actually had a website for the group Hanson (MMMBop...) {you can laugh now LOL}.. Nothing I brag about to anyone hahaa... my site was actually featured in some of their autobiographies, fan newsletters, magazines, etc.. I didn't think anything of it at the time (and my son recently colored in the books that I was featured in... awesome). I am finally getting it (sort of) but its just those first few hours when the codes you don't understand look like a foreign language from outer space.. then I see everyone here on the boards talking in PHP and I wanna pull my hair out because I don't translate yet! I'll get it.. just posted another problem tho LOL regarding a noteboard issue.. ergh!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.