PHP:
<?php
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect('localhost',"******","******") or die ("Couldn't connect!");
mysql_select_db('garrette_login') or die("Couldn't Log In!");
is the code. I have a system in which the user inputs a username and password in the field, and it's supposed to connect to my database if both fields have characters, and the user clicked submit. However, I get the error message which states "Couldn't Log In!". Anyone know why? I can't figure it out. Am I using a wrong command? I am still fairly new to php, so any help would be appreciated!
I fixed that problem, turns out that I hadn't added the account to the database -.- but I have another problem, and I don't want to fill the threads with all my problems :/
This one has stumped me. Right now I am trying to create a "members" only part of my site. Here is the full code, sorry it's a bit longish.
PHP:
<?php
session_start();
if ($_SESSION['username'])
{ print("
<HTML>
<HEAD>
<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<TITLE> Friend Zone</TITLE>
<link HREF=\"friendzonestylesheet.css\" rel=\"stylesheet\" type=\"text/css\" />
</HEAD>
<BODY>
<div id=\"container\">
<div id=\"header\">
<IMG SRC=\"FriendZoneheader.jpg\" HEIGHT=\"100\" WIDTH=\"100%\">
</div>
<div id=\"maincontainer\">
<div id=\"sidebar\">
<Center> <H2> Site Menu </H2> </center>
<p>All site menu options are hidden from Non-Users. Log in to continue </p>
<p><IMG SRC=\"friendzone.jpg\" ALT=\"Turco\" width=\"180\" height=\"282\" /></p>
</div>
<div id=\"content\">
<h1>What is <I> Friend Zone</I>? </H1> <p>A future alternative to social networking
sites such as facebook and myspace. This site will have similar features, but without all the
useless updates and hopefully faster loading times. When completed, this site will feature
many useful functions, but also maintain simplicity. </p>
<p class=\"style2\"> I am working on this by myself, so this may take a while. </p>
<p> Below I will allow some users to register to try this site ahead of time. Only a
small amount will be allowed, because I can't manage all the information at this stage
of development. If interested, fill in the fields below. </p>
<p class=\"style1\">(Only works if I have you inserted into the database) </p>
<form action='login.php' method='POST'>
Username:<input type='text' name='username'><br>
Password:<input type='password' name='password'><br>
<input type='submit' value='Log in'>
</form>
</div>
</div>
<div id=\"footer\">
© 2012 Garrett Emrick
</div>
</BODY>
</HTML>");
}
else
die("You must be logged in to view this page!");
?>
Now I believe the problem may be that I need to use "print" more often throughout this code, but I have no idea how to incorporate html with php. . . as in I don't know how I would include all this code. I would love it if someone would show a few examples of where or what I should do, or know a resource I could use to help me.
Wow. I am such a noob at this. I realized what I did wrong. I originally had this as a html file. Then I added the PHP so I could restrict non-logged in users from accessing it. However, when I did this I needed to also switch the file from an html, to a php. This is a fix for me, but if anyone with more knowledge than me thinks this is a wrong way to do it, please say so. I spent so long trying to fix this, and after posting it I immediately realized what I did. Maybe someone else can learn from my mistake? Haha.
Last edited: