ryanwood4 Posted February 20, 2009 Share Posted February 20, 2009 I have been set the task to create a login page/registration page. I have created a database named: MemberDirectory with two tables: Login and Membership. I am using the host: HostJunkie.co.uk which provides an admin area with phpMyAdmin, and allows me to create databases quite easily. However after writing the code for the login and registration page, it seems the two won't connect (www.rawtees.co.uk/login.php) Anyone know why or do I need to post anything else to help, i.e. the PHP program code. I new to all this, and would appreciate any help you could provide. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 20, 2009 Share Posted February 20, 2009 Post any error messages if you get any and the part of code responsible for connecting to database server (remember to remove any sensitive information, like passwords) Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 This is the connection code: (note: the ?????? is sensitive information which has been removed!) <?php /* Program: Login.php Desc: Login program for the members only section. */ session_start(); session_register('auth'); session_register('logname'); include("??????.inc"); switch (@$do) { case "login": $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $sql = "SELECT loginName FROM Member WHERE loginNames='$fusername'"; $result = mysql_query($sql) or die("Couldn't execute query."); $num = mysql_num_rows($result); if ($num == 1) // login name was found { $sql = "SELECT loginName FROM Member WHERE loginName='$fusername' AND password=password('$fpassword')"; $result2 = mysql_query($sql) or die("Couldn't execute query."); $num2 = mysql_num_rows($result2); if ($num2 > 0) // password is correct { Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 20, 2009 Share Posted February 20, 2009 Doesn't look wrong, but try adding this: error_reporting(E_ALL); ini_set('display_errors','On'); just after <?php and see if any error messages appear. Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 Nope, no error messages. Maybe my host is wrong, I have used localhost because it worked when I tested the connection? Could this be the cause? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 20, 2009 Share Posted February 20, 2009 Try changing switch (@$do) to switch ($_GET['do']) Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 Now i get this: Parse error: syntax error, unexpected ')', expecting ':' or '{' in /home/rawtees/public_html/login.php on line 11 Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 20, 2009 Share Posted February 20, 2009 Please post the changed code. Preferrably putting it into tags Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 This is the entire code: <?php error_reporting(E_ALL); ini_set('display_errors','On'); /* Program: Login.php Desc: Login program for the members only section. */ session_start(); session_register('auth'); session_register('logname'); include("data.inc"); switch ($_GET['do'])) { case "login": $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $sql = "SELECT loginName FROM Member WHERE loginNames='$fusername'"; $result = mysql_query($sql) or die("Couldn't execute query."); $num = mysql_num_rows($result); if ($num == 1) // login name was found { $sql = "SELECT loginName FROM Member WHERE loginName='$fusername' AND password=password('$fpassword')"; $result2 = mysql_query($sql) or die("Couldn't execute query."); $num2 = mysql_num_rows($result2); if ($num2 > 0) // password is correct { $auth="yes"; $logname=$fusername; $today = date("Y-m-d h:m:s"); $sql = "INSERT INTO LOGIN (loginName, loginTime) VALUES ('$logname','$today')"; mysql_query($sql) or die("Can't execute query."); header("Location: Member_page.php"); } else //password is not correct { unset($do); $message="The Login Name, '$fusername' exists, but you have not entered the correct password! Please try again.<br>"; include("login_form.inc"); } } elseif ($num == 0) // login name not found { unset($do); $message = "The Login Name you entered does not exist! Please try again.<br>"; include("login_form.inc"); } break; case "new"; foreach($HTTP_POST_VARS as $key => $value) { if ($key != "fax") { if ($value == "") { unset($do); $message_new = "Required information is missing. Please try again."; include("login_form.inc"); exit(); } } if (ereg("{Name)",$key)) { if (!ereg("^[A-Za-z' -]{1,50}$",$key)) { unset($do); $message_new = "$lastName is not valid name. Please try again."; include("login_form.inc"); exit(); } } $$key = strip_tags(trim($value)); } if (!ereg("^.+@.+\\..+$",$email)) { unset($do); $message_new = "$email_address is not a valid email address. Please try again."; include("login_form.inc"); exit(); } /* check to see if the login name already exists */ $connection = mysql_connect($host, $user, $password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $sql = "SELECT loginName FROM Member WHERE loginName='$newname'"; $result = mysql_query($sql) or die("Couldn't execute query."); $num = mysql_numrows($result); if ($num > 0) { unset($do); $message_new = "$newname already used. Select another Member ID."; include("login_form.inc"); exit(); } else { $today = time("Y-m-d"); $sql = "INSERT INTO Member (loginName,createdate,password,first_name,second_name,description) VALUES ('$newname','$today',password('$newpass'), '$first_name', '$second_name', '$email_address', '$description')"; mysql_query($sql); $auth="yes"; $logname = $newname; /* Send email to new member */ $emess1="A new member account has been setup for you. "; $emess2="Your new member ID and password are: "; $emess3="\n\n\t$newname\n\t$newpass\n\n"; $emess4="We appreciate your membership "; $emess5="at RawTees.co.uk\n\n"; $emess6="If you have any queries or questions please email: "; $emess7="ryan.wood@rawtees.co.uk"; $emess = $emess1.$emess2.$emess3.$emess4.$emess5.$emess6.$emess7; $ehead="From: membership@rawtees.co.uk\r\n"; $subject = "Your new member account at RawTees."; $mailsend=mail("$email_address","$subject","$emess","$ehead"); header("Location: new_member.php"); } break; default: include("login_form.inc"); } ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 20, 2009 Share Posted February 20, 2009 switch ($_GET['do'])) there are two )) in this line. Should only be one ) Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 Okay i now get this: Notice: Undefined index: do in /home/rawtees/public_html/login.php on line 11, but the page still loads. and now when i enter info into the login forms it says "Couldn't select database" Quote Link to comment Share on other sites More sharing options...
ryanwood4 Posted February 20, 2009 Author Share Posted February 20, 2009 Ok, thanks so much for your help, your help has sorted it out now. One more thing that now pops up is this: Notice: Undefined variable: fusername in /home/rawtees/public_html/login.php on line 19 Couldn't execute query. Any suggestions. Line 19 is WHERE loginName='$fusername'"; Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 20, 2009 Share Posted February 20, 2009 Change $sql = "SELECT loginName FROM Member WHERE loginNames='$fusername'"; to $fusername = mysql_real_escape_string($_POST['fusername']); $sql = "SELECT loginName FROM Member WHERE loginNames='$fusername'"; Quote Link to comment 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.