Jump to content

Can You Check My Code


chocopi

Recommended Posts

Well I was wondering if it would be possible for someone to check the codes of three of my pages. I believe that my pages are mis-matched and have long-winded codes. I am new to php so I am unable to check my pages efficiently. Also, as I have only recently discovered phpFreaks my code comes from various sources making pages a shamble. So if you would not mind sieving through my code and making changes to it so that it is more professional and more accurate then I would be thankful.

 

index.php

<?php

$title = 'Index';

require_once ('page_header.php');

require_once ('login.php');

require_once ('page_footer.php');

?>

 

 

login.php

<?php

require_once ('page_header.php');

session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "SELECT * FROM users WHERE username='$username' && password='$password'";

$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {
$error = 'Bad Login';

print("<form name=\"login\" method=\"post\" action=\"$PHP_SELF\"> \n");
print("<table border=\"0\" width=\"225\" align=\"center\"> \n");
print("    <tr> \n");
print("        <td width=\"219\" bgcolor=\"#999999\"> \n");
print("            <p align=\"center\"><font color=\"white\"><span style=\"font-size:12pt;\"><b>Login</b></span></font></p> \n");
print("        </td> \n");
print("    </tr> \n");
print("    <tr> \n");
print("        <td width=\"219\"> \n");
print("            <table border=\"0\" width=\"220\" align=\"center\"> \n");
print("                <tr> \n");
print("                    <td width=\"71\" align=\"center\"><span style=\"font-size:12pt;\">Username:</span></td> \n");
print("                    <td width=\"139\"><input type=\"text\" name=\"username\" value=\"$username\"></td> \n");
print("                </tr> \n");
print("                <tr> \n");
print("                    <td width=\"71\" align=\"center\"><span style=\"font-size:12pt;\">Password:</span></td> \n");
print("                    <td width=\"139\"><input type=\"password\" name=\"password\" value\"\"></td> \n");
print("                </tr> \n");
print("                <tr> \n");
print("                    <td width=\"71\"> </td> \n");
print("                        <td width=\"139\"> \n");
print("                            <p align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Submit\"></p> \n");
print("                        </td> \n");
print("                </tr> \n");
print("	        <tr>  \n");
print("                    <td colspan=\"2\" align=\"center\"><a href=\"forgetpass.php\">Forgotten Password?</a></td> \n");
print("                </tr> \n");
print("            </table> \n");
print("        </td> \n");
print("    </tr> \n");
print("    <tr> \n");
print("        <td width=\"219\" bgcolor=\"#999999\" align=\"center\"><font color=\"white\">Not Registered? </font><a href=\"registration.php\" target=\"_self\"><font color=\"white\">Register</font></a><font color=\"white\"> </font><b><i><font color=\"white\">Now!</font></i></b></td> \n");
print("    </tr> \n");
print("</table> \n");
print("</form> \n");

	if($_POST){
		print ("<font color=\"#ff0000\"> \n");
		print ("<center> \n");
		echo ("Incorrect Username and Password combination.");
		print ("</center> \n");
		print ("</font> \n");
		require_once ('page_footer.php');
	}

} else {
    $_SESSION['username'] = '$username';
    require_once ('memberspage.php');
}

?>

 

memberspage.php (I think this page is most messed up)

<?php

$title = 'Members Page';

require_once ('page_header.php');

$user = ucfirst($username);


// members page


if ( empty( $username ) ) {

print ("Please login below!");

require_once ('login.php');

} else
$active = mysql_query("SELECT active FROM users WHERE username='$username'");
while($row = mysql_fetch_array($active))
{
if($row['active'] == 0) {
print ("<br /> \n");
print ("<center> \n");
print ("$user, you must activate your account via the email that you provided or you will not be able to continue. \n");
print ("<br /> \n");
print ("<a href=\"$root\n");
print("logout.php\">Return to Home Page</a> \n");
print ("</center> \n");
} else

if($row['active'] > 0) {

$id = mysql_query("SELECT id FROM users WHERE username='$username'");
$email = mysql_query("SELECT email FROM users WHERE username='$username'");
$class = mysql_query("SELECT class FROM users WHERE username='$username'");

print ("<br /> \n");
print ("<center> \n");
print("Welcome $user (#");
while($row = mysql_fetch_array($id))
	 {
print $row['id'];
}
print("), you signed up with the email address: <a href=\"mailto:");
while($row = mysql_fetch_array($email))
	 {
  	print $row['email'];
print ("\">");
  	print $row['email'];
}
print ("</a>.");
print ("<br /> \n");
	while($row = mysql_fetch_assoc($class))
		{
			$cls = $classes[$row['class']];
		echo "Your class is $cls\n";
		}
print ("<br /> \n");
print("<a href=\"$root\n");
print("edit_profile.php?\n");
require_once ('edit_profile_link.php');
print("\">Edit Profile</a>\n");

print ("<br /> \n");
print ("<br /> \n");
print ("<a href=\"$root\n");
print("logout.php\">Logout</a> \n");
print ("</center> \n");


}

}

require_once ('page_footer.php');

?>

 

I don't understand sessions at all, which is quite a problem (even though I have looked on php.net) so all the pages have are session_start();

 

If you can help then please don't bother with changing all the print(""); into a new template html file and using include(); as I prefer the work being in one page.

 

Thankyou very much and if you need to ask any questions about it, please do so.

 

~ Chocopi

Link to comment
Share on other sites

personally... i suggest you learn and master the basics of php... before you start to build long-winded codes... once you can do the small things perfectly... then you can do the big things perfectly... :D

 

you cant expect everyone else to do your work forever... ;)

 

no offence intended :)

Link to comment
Share on other sites

I see what you mean and learning php is on my to-do list, but for me to learn stuff I need to see how it is done first and not just read about it.

 

Also, I don't want users to completly write the code for me as thats just rude, but I would just like for someone to change the rubbish I have there into something that is proper and not a jumble.

 

PS. The code I wouldn't say is long-winded because it is just meant to be a simple login which tells the user the information they registered involving sessions and what not. Then I hopefully will be able to expand and learn more and more. Well thats the plan ;D

 

~ Chocopi

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.