Hey everyone, I have a bit of a problem.
I'm trying to create a site where you can create an account, enter your length and weight and with it it calculates your BMI, or Body Mass Index.
If it detects you are overweight(A BMI of more than 25) it calculates how much you have to lose in order to get a good BMI, or even that you can enter your desired BMI and it calculates how much you have to lose.
Thing is... I'm already at a dead end with the login script. I've just started in PHP and SQL, but I have coded in C++ a lot before. I actually made a similar program to what I'm doing now in C++.
I'll try to give you as much code as I can.
This is the form:
As you can see, most of it is useless images for the layout.
This is my login-exec.php script:
If you need any further information, please ask and I will provide it.
I'm trying to create a site where you can create an account, enter your length and weight and with it it calculates your BMI, or Body Mass Index.
If it detects you are overweight(A BMI of more than 25) it calculates how much you have to lose in order to get a good BMI, or even that you can enter your desired BMI and it calculates how much you have to lose.
Thing is... I'm already at a dead end with the login script. I've just started in PHP and SQL, but I have coded in C++ a lot before. I actually made a similar program to what I'm doing now in C++.
I'll try to give you as much code as I can.
This is the form:
Code:
<html> <head> <title>My Weight Coach</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#5c5c5c" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <!-- ImageReady Slices (MWCMWC.psd) --> <table id="Table_01" width="1024" height="769" border="0" cellpadding="0" cellspacing="0" align ="center"> <tr> <td colspan="2" rowspan="2"> <img src="images/MWCMWC_01.png" width="613" height="115" alt=""></td> <td> <a href = "http://sanderson.bc-inf.nl/MWCLO.html"><img src="images/MWChome_02.png" width="137" height="49" border="0" alt=""></a></td> <td colspan="2"> <img src="images/MWCMWC_03.png" width="137" height="49" alt=""></td> <td> <a href = "http://sanderson.bc-inf.nl/MWChome.html"><img src="images/MWCLO_04.png" width="137" height="49" border = "0" alt=""></a></td> </tr> <tr> <td colspan="4"> <img src="images/MWCMWC_05.png" width="411" height="66" alt=""></td> </tr> <tr> <td rowspan="2"> <img src="images/MWChome_06.png" width="137" height="653" alt=""></td> <td colspan="3" background = "images/MWChome_07.png" width="730" height="585" alt=""> <form id="loginForm" name="loginForm" method="post" action="login-exec.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="112"><b>Login</b></td> <td width="188"><input name="login" type="text" class="textfield" id="login" /></td> </tr> <tr> <td><b>Password</b></td> <td><input name="password" type="password" class="textfield" id="password" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Login" /></td> </tr> </table> </form> </td> <td colspan="2" rowspan="2"> <img src="images/MWChome_08.png" width="157" height="653" alt=""></td> </tr> <tr> <td colspan="3"> <img src="images/MWChome_09.png" width="730" height="68" alt=""></td> </tr> <tr> <td> <img src="images/spacer.gif" width="137" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="476" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="137" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="117" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="20" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="137" height="1" alt=""></td> </tr> </table> <!-- End ImageReady Slices --> </body> </html>
This is my login-exec.php script:
Code:
<?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: http://sanderson.bc-inf.nl/member-index.php"); exit(); }else { //Login failed header("location: http://sanderson.bc-inf.nl/login-failed.php"); exit(); } }else { die("Query failed"); } ?>
Comment