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!!!