stublackett Posted February 14, 2008 Share Posted February 14, 2008 Hi, I've got the variable of $message which is initially set as a welcome message to the site I then have a login script, Which works (As far as I know) But I'd like the script to output the message welcome to the site '$username' The message when you login incorrectly works, It outputs the message "Invalid Username or Password" But when the login is true, I get the message in the address bar, But not Where the echo statement is set to be in the HTML script Any ideas or help would be very useful <?php session_start(); $message = 'Welcome to the Dragons Den <br /> <br /> This site has been setup with enterepeneurs in mind, The site will give you; the entrepeneur the chance to offer your business ideas to the Dragons, In the hope of gaining an investment <br /> <br /> Good Luck'; //LoginForm using HEREDOC $loginform = <<<LOGINFORM <div id="login"> <form method="post" action="" login=true"> <fieldset> <div> <label for="username">User Name :</label> <input type="text" name="username" id="username" class="txt" /> </div> <div> <label for="fullname">Password : </label> <input type="password" name="password" id="password" class="txt" /> </div> </fieldset> <div> <input type="submit" name="Submit" id="Submit" value="Login" class="btn" /> </div> </fieldset> </form> </div> LOGINFORM; include ("dbconnect.php"); session_start(); // Connect to server and select databse. mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); if (isset($_POST['Submit'])) { // username and password sent from signup form $username=stripslashes($_POST['username']); $password=stripslashes($_POST['password']); $sql="SELECT * FROM $db_table WHERE username='" . mysql_real_escape_string($username) . "' and password='" . mysql_real_escape_string($password) . "'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ //Register Username and Password $_SESSION['username'] = $username; $_SESSION['password'] = $password; $message = 'You have successfully logged in <br />Welcome to the Dragons Den $username'; header("location: index.php?message=$message"); exit(); // always use the exit after a header to prevent the rest of the script from executing } else { $message = "Invalid Username or Password"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The Dragons Den - Home For The Budding Entrepeneur</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <link href="loginstyles.css" rel="stylesheet" type="text/css" /> <style type="text/css"> </style> </head> <body> <div id="site-background"> <div id="left-side"></div> <div id="site-logo"></div> <div id="top-menu"></div> <div id="home-btn"><a href="index.html"><img src="images/home_btn.jpg" alt="Home" width="94" height="59" border="0" /></a></div> <div id="about-btn"><a href="about.html"><img src="images/about_btn.jpg" alt="About" width="94" height="59" border="0" /></a></div> <div id="info-btn"><a href="info.html"><img src="images/info_btn.jpg" alt="Info" width="94" height="59" border="0" /></a></div> <div id="contact-btn"><a href="contact.html"><img src="images/contact_btn.jpg" alt="Contact" width="94" height="59" border="0" /></a></div> <div id="users-btn"><a href="users.html"><img src="images/users_btn.jpg" alt="Users" width="119" height="60" border="0" /></a></div> <div id="navigation"> <ul class="style8"> <li><a title="Home" href="index.html">Home</a> </li> <li><a title="The Dragons" href="thedragons.html">The Dragons</a> </li> <li><a title="Entrepeneurs" href="entrepeneurs.html">Entrepeneurs</a> </li> <li><a title="Ideas" href="ideas.html">Ideas</a> </li> <li><a title="Discuss Ideas" href="ideas.html">Discuss Ideas</a> </li> <li><a title="Upload Ideas" href="upload.html">Upload Ideas </a></li> <li><a title="Contact" href="contact.html">Contact The Webmaster </a> </li> </ul> </div> <div class="main-content" id="middle-content"><img src="images/welcome_header.jpg" alt="Welcome" width="504" height="25" /> <?php echo $message ; ?> </div> <div> <?php echo $loginform ; ?> </div> <div id="search-field"> <label> <input name="textfield" type="text" id="textfield" size="18" /> </label> <span class="style7"><a href="search.html">SEARCH</a></span></div> <div id="shadow"></div> <div class="style7" id="footer">| Sitemap | Contact | © Stuart Blackett</div> <div id="logo"><img src="images/site-dragon.gif" alt="The Dragons Den" width="245" height="148" /></div> </div> </body> </html> Thanks (edited by kenrbnsn to change the tags to ) Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 14, 2008 Share Posted February 14, 2008 Try this: <?php session_start(); if(isset($_GET['message'] == 'true') { echo $message = 'Welcome to the Dragons Den <br /> <br /> This site has been setup with enterepeneurs in mind, The site will give you; the entrepeneur the chance to offer your business ideas to the Dragons, In the hope of gaining an investment <br /> <br /> Good Luck'; } //LoginForm using HEREDOC $loginform = <<<LOGINFORM <div id="login"> <form method="post" action="" login=true"> <fieldset> <div> <label for="username">User Name :</label> <input type="text" name="username" id="username" class="txt" /> </div> <div> <label for="fullname">Password : </label> <input type="password" name="password" id="password" class="txt" /> </div> </fieldset> <div> <input type="submit" name="Submit" id="Submit" value="Login" class="btn" /> </div> </fieldset> </form> </div> LOGINFORM; include ("dbconnect.php"); session_start(); // Connect to server and select databse. mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); if (isset($_POST['Submit'])) { // username and password sent from signup form $username=stripslashes($_POST['username']); $password=stripslashes($_POST['password']); $sql="SELECT * FROM $db_table WHERE username='" . mysql_real_escape_string($username) . "' and password='" . mysql_real_escape_string($password) . "'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ //Register Username and Password $_SESSION['username'] = $username; $_SESSION['password'] = $password; $message = 'You have successfully logged in <br />Welcome to the Dragons Den $username'; header("location: index.php?message=true"); exit(); // always use the exit after a header to prevent the rest of the script from executing } else { $message = "Invalid Username or Password"; } } ?> Quote Link to comment Share on other sites More sharing options...
foreverhex Posted February 14, 2008 Share Posted February 14, 2008 Try replacing: <?php echo $message ; ?> with <?php echo $_GET[message] ; ?> but if you do that your login message will be broken... Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 That appears to work, Thanks! But for some bizzare reason, The positioning of the text is at the top of the page (Above everything) AND in the HTML <DIV> tag Any ideas there? Seems strange because its doing exactly the same as the "Invalid Username or Password" and the Variable is exactly the same Not to worry if no-one knows, As your not HTML programmers Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 14, 2008 Share Posted February 14, 2008 Wich one worked? If mine,place this in the html body where you want the message to appear <?php if(isset($_GET['message'] == 'true') { echo $message = 'Welcome to the Dragons Den <br /> <br /> This site has been setup with enterepeneurs in mind, The site will give you; the entrepeneur the chance to offer your business ideas to the Dragons, In the hope of gaining an investment <br /> <br /> Good Luck'; } ?> Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 Wich one worked? If mine,place this in the html body where you want the message to appear <?php if(isset($_GET['message'] == 'true') { echo $message = 'Welcome to the Dragons Den <br /> <br /> This site has been setup with enterepeneurs in mind, The site will give you; the entrepeneur the chance to offer your business ideas to the Dragons, In the hope of gaining an investment <br /> <br /> Good Luck'; } ?> That works... BUT The message you've got in there, I want that to say "Succesfully logged in to the site" So I've changed that to match! As well as that, The Invalid Username or Password has also dissapeared :-\ But I now have the problem of that text : Welcome to the Dragons Den This site has been setup with enterepeneurs in mind, The site will give you; the entrepeneur the chance to offer your business ideas to the Dragons, In the hope of gaining an investment Not loading at all, Tried setting the if(isset($_GET['message']) == 'false') But no joy there either Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 14, 2008 Share Posted February 14, 2008 I don't understand what are you really doing, but i suggest using functions, when you send an html form to the same page, and integrating the php with the html, send me a copy of your code, i will tell you how Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 Ok, The idea is (I hope to get to this eventually) But doing it piece by piece first The bit where it says Welcome to the Dragons Den This site has been setup with enterepeneurs in mind, The site will give you; the entrepeneur the chance to offer your business ideas to the Dragons, In the hope of gaining an investment Good Luck Is the sites "Blurb" as its what you see on the index page, Thinking about it now, That will have to change as the login will appear on each page, Which could be very tricky I agree that this should be attached as a form action rather than in the script, So maybe the login form part of my HTML should have the action of "checklogin.php" then it directs to the PHP Script The issue seems to be with the header (location : index.php?message=$message) The full script for this idea, Is above! I've tried this before but I was getting constant header errors, So I'm trying to put it all into the page instead, Which seemed the best idea at the time.. Obviously not now But if your after the code HTML and PHP its all in my first post Thanks Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 14, 2008 Share Posted February 14, 2008 Try this: <?php //LoginForm using HEREDOC include ("dbconnect.php"); $message = 'Welcome to the Dragons Den '; function Submit() { session_start(); // Connect to server and select databse. mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); if (isset($_POST['Submit'])) { // username and password sent from signup form $username=stripslashes($_POST['username']); $password=stripslashes($_POST['password']); $sql="SELECT * FROM $db_table WHERE username='" . mysql_real_escape_string($username) . "' and password='" . mysql_real_escape_string($password) . "'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { //Register Username and Password $_SESSION['username'] = $username; $_SESSION['password'] = $password; $message = 'You have successfully logged in <br />Welcome to the Dragons Den $username'; DysplayDefault($message); } else { $message = "Invalid Username or Password"; DysplayDefault($message); } } } function DisplayDefault($message) { echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The Dragons Den - Home For The Budding Entrepeneur</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <link href="loginstyles.css" rel="stylesheet" type="text/css" /> <style type="text/css"> </style> </head> <body> <div id="site-background"> <div id="left-side"></div> <div id="site-logo"></div> <div id="top-menu"></div> <div id="home-btn"><a href="index.html"><img src="images/home_btn.jpg" alt="Home" width="94" height="59" border="0" /></a></div> <div id="about-btn"><a href="about.html"><img src="images/about_btn.jpg" alt="About" width="94" height="59" border="0" /></a></div> <div id="info-btn"><a href="info.html"><img src="images/info_btn.jpg" alt="Info" width="94" height="59" border="0" /></a></div> <div id="contact-btn"><a href="contact.html"><img src="images/contact_btn.jpg" alt="Contact" width="94" height="59" border="0" /></a></div> <div id="users-btn"><a href="users.html"><img src="images/users_btn.jpg" alt="Users" width="119" height="60" border="0" /></a></div> <div id="navigation"> <ul class="style8"> <li><a title="Home" href="index.html">Home</a> </li> <li><a title="The Dragons" href="thedragons.html">The Dragons</a> </li> <li><a title="Entrepeneurs" href="entrepeneurs.html">Entrepeneurs</a> </li> <li><a title="Ideas" href="ideas.html">Ideas</a> </li> <li><a title="Discuss Ideas" href="ideas.html">Discuss Ideas</a> </li> <li><a title="Upload Ideas" href="upload.html">Upload Ideas </a></li> <li><a title="Contact" href="contact.html">Contact The Webmaster </a> </li> </ul> </div> <div class="main-content" id="middle-content"><img src="images/welcome_header.jpg" alt="Welcome" width="504" height="25" />'.$message; echo'</div> <div> <div id="login"> <form method="post" action="'.RewriteLink('yourpage.php');.'" "> <fieldset> <div> <label for="username">User Name :</label> <input type="text" name="username" id="username" class="txt" /> <input type="hidden" name="login" id="login" value="true"/> <input type="hidden" name="action" value="Submit"/> </div> <div> <label for="fullname">Password : </label> <input type="password" name="password" id="password" class="txt" /> </div> </fieldset> <div> <input type="submit" name="Submit" id="Submit" value="Login" class="btn" /> </div> </fieldset> </form> </div> </div> <div id="search-field"> <label> <input name="textfield" type="text" id="textfield" size="18" /> </label> <span class="style7"><a href="search.html">SEARCH</a></span></div> <div id="shadow"></div> <div class="style7" id="footer">| Sitemap | Contact | © Stuart Blackett</div> <div id="logo"><img src="images/site-dragon.gif" alt="The Dragons Den" width="245" height="148" /></div> </div> </body> </html>'; } $action = isset($_POST['action']); switch($action) { case 'Submit': Submit(); break; default: DisplayDefault($message); } ?> Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 Parse error: syntax error, unexpected '.' on line 87 Which is : <form method="post" action="'.RewriteLink('yourpage.php');.'" "> Not quite sure what that bit of the page is supposed to be doing? I've tried changing the file to "checklogin.php" but still got that Parse Error Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 14, 2008 Share Posted February 14, 2008 Sorry! <?php //LoginForm using HEREDOC include ("dbconnect.php"); $message = 'Welcome to the Dragons Den '; function Submit() { session_start(); // Connect to server and select databse. mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); if (isset($_POST['Submit'])) { // username and password sent from signup form $username=stripslashes($_POST['username']); $password=stripslashes($_POST['password']); $sql="SELECT * FROM $db_table WHERE username='" . mysql_real_escape_string($username) . "' and password='" . mysql_real_escape_string($password) . "'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { //Register Username and Password $_SESSION['username'] = $username; $_SESSION['password'] = $password; $message = 'You have successfully logged in <br />Welcome to the Dragons Den $username'; DysplayDefault($message); } else { $message = "Invalid Username or Password"; DysplayDefault($message); } } } function DisplayDefault($message) { echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The Dragons Den - Home For The Budding Entrepeneur</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <link href="loginstyles.css" rel="stylesheet" type="text/css" /> <style type="text/css"> </style> </head> <body> <div id="site-background"> <div id="left-side"></div> <div id="site-logo"></div> <div id="top-menu"></div> <div id="home-btn"><a href="index.html"><img src="images/home_btn.jpg" alt="Home" width="94" height="59" border="0" /></a></div> <div id="about-btn"><a href="about.html"><img src="images/about_btn.jpg" alt="About" width="94" height="59" border="0" /></a></div> <div id="info-btn"><a href="info.html"><img src="images/info_btn.jpg" alt="Info" width="94" height="59" border="0" /></a></div> <div id="contact-btn"><a href="contact.html"><img src="images/contact_btn.jpg" alt="Contact" width="94" height="59" border="0" /></a></div> <div id="users-btn"><a href="users.html"><img src="images/users_btn.jpg" alt="Users" width="119" height="60" border="0" /></a></div> <div id="navigation"> <ul class="style8"> <li><a title="Home" href="index.html">Home</a> </li> <li><a title="The Dragons" href="thedragons.html">The Dragons</a> </li> <li><a title="Entrepeneurs" href="entrepeneurs.html">Entrepeneurs</a> </li> <li><a title="Ideas" href="ideas.html">Ideas</a> </li> <li><a title="Discuss Ideas" href="ideas.html">Discuss Ideas</a> </li> <li><a title="Upload Ideas" href="upload.html">Upload Ideas </a></li> <li><a title="Contact" href="contact.html">Contact The Webmaster </a> </li> </ul> </div> <div class="main-content" id="middle-content"><img src="images/welcome_header.jpg" alt="Welcome" width="504" height="25" />'.$message; echo'</div> <div> <div id="login"> <form method="post" action="'.RewriteLink('yourpage.php').'" "> <fieldset> <div> <label for="username">User Name :</label> <input type="text" name="username" id="username" class="txt" /> <input type="hidden" name="login" id="login" value="true"/> <input type="hidden" name="action" value="Submit"/> </div> <div> <label for="fullname">Password : </label> <input type="password" name="password" id="password" class="txt" /> </div> </fieldset> <div> <input type="submit" name="Submit" id="Submit" value="Login" class="btn" /> </div> </fieldset> </form> </div> </div> <div id="search-field"> <label> <input name="textfield" type="text" id="textfield" size="18" /> </label> <span class="style7"><a href="search.html">SEARCH</a></span></div> <div id="shadow"></div> <div class="style7" id="footer">| Sitemap | Contact | © Stuart Blackett</div> <div id="logo"><img src="images/site-dragon.gif" alt="The Dragons Den" width="245" height="148" /></div> </div> </body> </html>'; } $action = isset($_POST['action']); switch($action) { case 'Submit': Submit(); break; default: DisplayDefault($message); } ?> Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 Its showing the page, But giving me the error : Fatal error: Call to undefined function RewriteLink() on line 87 Line 87 contains the following : <form method="post" action="'.RewriteLink('yourpage.php').'""> I thought originally there was too many quotation marks within it, But the same error appeared in there Thanks very much for your continued help! These forums should have an exalt or smite on em' or something like that! Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 14, 2008 Share Posted February 14, 2008 <form method="post" action="yourpage.php"> Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 I changed "yourpage.php" to "checklogin.php" and copied some of the script that was duplicating I'm still getting an error : Fatal error: Call to undefined function DisplayDefault() on line 101 Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 14, 2008 Share Posted February 14, 2008 I think it was becouse the function DisplayDefault was called before being declared, it was my error, please change your code to this <?php //LoginForm using HEREDOC include ("dbconnect.php"); $message = 'Welcome to the Dragons Den '; function DisplayDefault($message) { echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The Dragons Den - Home For The Budding Entrepeneur</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <link href="loginstyles.css" rel="stylesheet" type="text/css" /> <style type="text/css"> </style> </head> <body> <div id="site-background"> <div id="left-side"></div> <div id="site-logo"></div> <div id="top-menu"></div> <div id="home-btn"><a href="index.html"><img src="images/home_btn.jpg" alt="Home" width="94" height="59" border="0" /></a></div> <div id="about-btn"><a href="about.html"><img src="images/about_btn.jpg" alt="About" width="94" height="59" border="0" /></a></div> <div id="info-btn"><a href="info.html"><img src="images/info_btn.jpg" alt="Info" width="94" height="59" border="0" /></a></div> <div id="contact-btn"><a href="contact.html"><img src="images/contact_btn.jpg" alt="Contact" width="94" height="59" border="0" /></a></div> <div id="users-btn"><a href="users.html"><img src="images/users_btn.jpg" alt="Users" width="119" height="60" border="0" /></a></div> <div id="navigation"> <ul class="style8"> <li><a title="Home" href="index.html">Home</a> </li> <li><a title="The Dragons" href="thedragons.html">The Dragons</a> </li> <li><a title="Entrepeneurs" href="entrepeneurs.html">Entrepeneurs</a> </li> <li><a title="Ideas" href="ideas.html">Ideas</a> </li> <li><a title="Discuss Ideas" href="ideas.html">Discuss Ideas</a> </li> <li><a title="Upload Ideas" href="upload.html">Upload Ideas </a></li> <li><a title="Contact" href="contact.html">Contact The Webmaster </a> </li> </ul> </div> <div class="main-content" id="middle-content"><img src="images/welcome_header.jpg" alt="Welcome" width="504" height="25" />'.$message; echo'</div> <div> <div id="login"> <form method="post" action="'.RewriteLink('yourpage.php').'" "> <fieldset> <div> <label for="username">User Name :</label> <input type="text" name="username" id="username" class="txt" /> <input type="hidden" name="login" id="login" value="true"/> <input type="hidden" name="action" value="Submit"/> </div> <div> <label for="fullname">Password : </label> <input type="password" name="password" id="password" class="txt" /> </div> </fieldset> <div> <input type="submit" name="Submit" id="Submit" value="Login" class="btn" /> </div> </fieldset> </form> </div> </div> <div id="search-field"> <label> <input name="textfield" type="text" id="textfield" size="18" /> </label> <span class="style7"><a href="search.html">SEARCH</a></span></div> <div id="shadow"></div> <div class="style7" id="footer">| Sitemap | Contact | © Stuart Blackett</div> <div id="logo"><img src="images/site-dragon.gif" alt="The Dragons Den" width="245" height="148" /></div> </div> </body> </html>'; } function Submit() { session_start(); // Connect to server and select databse. mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); if (isset($_POST['Submit'])) { // username and password sent from signup form $username=stripslashes($_POST['username']); $password=stripslashes($_POST['password']); $sql="SELECT * FROM $db_table WHERE username='" . mysql_real_escape_string($username) . "' and password='" . mysql_real_escape_string($password) . "'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { //Register Username and Password $_SESSION['username'] = $username; $_SESSION['password'] = $password; $message = 'You have successfully logged in <br />Welcome to the Dragons Den $username'; DysplayDefault($message); } else { $message = "Invalid Username or Password"; DysplayDefault($message); } } } $action = isset($_POST['action']); switch($action) { case 'Submit': Submit(); break; default: DisplayDefault($message); } ?> Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 15, 2008 Author Share Posted February 15, 2008 No joy with that either....... I've been following an example that echo's quite a few $messages The example is as follows : if(!$email&&!$PassWord){ $message = "Both Form Fields Not Filled In!"; header("location: index.php?message=$message"); }elseif(!$email){ $message ="You did not fill in the User Name form field"; header("location: index.php?message=$message"); }elseif(!$PassWord){ $message = "You did not fill in the Password form field"; header("location: index.php?message=$message"); }else{ //Make our connection $Link = mysql_connect($Host, $User, $Password); //Query for email And PassWord. Select 1 record, where email is equal to VAR. $Query = "SELECT * FROM $table2 WHERE email = '$email'"; $Result = mysql_db_query ($DBName, $Query, $Link); //Check that the table contains the user name entered $num_rows= mysql_num_rows($Result); $PassWordMatch=mysql_fetch_array($Result); $Row = mysql_fetch_array($Result); if(!($num_rows)){ //Deliver String Variable For User Not Recognised $message = "Your Email Address Was Not Recongised, Please Try Again!"; header("location: index.php?message=$message"); }else{ //New Algorithim For Sha1 Password $str = $PassWord; $PassWord = sha1($str) ; if($PassWord !=$PassWordMatch['PassWord']){ //Deliver String Variable For Wrong Password $message = "You Entered The Wrong Password, Please Try Again!"; header("location: index.php?message=$message"); }else{ //Generate sessions //Note: for some reason the query has to be performed again in PHP5 $Query = "SELECT id, email, userType FROM $table2 WHERE email = '$email'"; $Result = mysql_db_query ($DBName, $Query, $Link); $Row = mysql_fetch_array($Result); $_SESSION['email'] = $Row['email']; $_SESSION['userID'] = $Row['id']; $_SESSION['userType'] = $Row['userType']; $message = "You are now logged in <br />Please continue to<br /> use the site!"; header("location: index.php?message=$message"); } } } } If this one works, Whats the difference between that and mine!? On mine, Its outputting the message in the address bar, But not where the <DIV> Tag is defined, I've made a new DIV tag called $errormessage, So that does'nt conflict anymore My code is now as follows <?php session_start(); //LoginForm using HEREDOC $loginform = <<<LOGINFORM <div id="login"> <form method="post" action="" login=true"> <fieldset> <div> <label for="username">User Name :</label> <input type="text" name="username" id="username" class="txt" /> </div> <div> <label for="fullname">Password : </label> <input type="password" name="password" id="password" class="txt" /> </div> </fieldset> <div> <input type="submit" name="Submit" id="Submit" value="Login" class="btn" /> </div> </fieldset> </form> </div> LOGINFORM; include ("dbconnect.php"); // Connect to server and select databse. mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); if (isset($_POST['Submit'])) { // username and password sent from signup form $username=stripslashes($_POST['username']); $password=stripslashes($_POST['password']); $sql="SELECT * FROM $db_table WHERE username='" . mysql_real_escape_string($username) . "' and password='" . mysql_real_escape_string($password) . "'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ //Register Username and Password $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("location:index.php?message=$message"); exit(); // always use the exit after a header to prevent the rest of the script from executing } else { $errormessage = "Invalid Username or Password"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The Dragons Den - Home For The Budding Entrepeneur</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <link href="loginstyles.css" rel="stylesheet" type="text/css" /> <style type="text/css"> </style> </head> <body> <div id="site-background"> <div id="left-side"></div> <div id="site-logo"></div> <div id="top-menu"></div> <div id="home-btn"><a href="index.html"><img src="images/home_btn.jpg" alt="Home" width="94" height="59" border="0" /></a></div> <div id="about-btn"><a href="about.html"><img src="images/about_btn.jpg" alt="About" width="94" height="59" border="0" /></a></div> <div id="info-btn"><a href="info.html"><img src="images/info_btn.jpg" alt="Info" width="94" height="59" border="0" /></a></div> <div id="contact-btn"><a href="contact.html"><img src="images/contact_btn.jpg" alt="Contact" width="94" height="59" border="0" /></a></div> <div id="users-btn"><a href="users.html"><img src="images/users_btn.jpg" alt="Users" width="119" height="60" border="0" /></a></div> <div id="navigation"> <ul class="style8"> <li><a title="Home" href="index.html">Home</a> </li> <li><a title="The Dragons" href="thedragons.html">The Dragons</a> </li> <li><a title="Entrepeneurs" href="entrepeneurs.html">Entrepeneurs</a> </li> <li><a title="Ideas" href="ideas.html">Ideas</a> </li> <li><a title="Discuss Ideas" href="ideas.html">Discuss Ideas</a> </li> <li><a title="Upload Ideas" href="upload.html">Upload Ideas </a></li> <li><a title="Contact" href="contact.html">Contact The Webmaster </a> </li> </ul> </div> <div id="loginerror"> <?php echo $errormessage ; ?> </div> <div class="main-content" id="middle-content"><img src="images/welcome_header.jpg" alt="Welcome" width="504" height="25" /> Welcome to the Dragons Den <br /> <br /> This site has been setup with enterepeneurs in mind, The site will give you; the entrepeneur the chance to offer your business ideas to the Dragons, In the hope of gaining an investment <br /> <br /> Good Luck </div> <div> <?php echo $loginform ; ?> </div> <div id="search-field"> <label> <input name="textfield" type="text" id="textfield" size="18" /> </label> <span class="style7"><a href="search.html">SEARCH</a></span></div> <div id="shadow"></div> <div class="style7" id="footer">| Sitemap | Contact | © Stuart Blackett</div> <div id="logo"><img src="images/site-dragon.gif" alt="The Dragons Den" width="245" height="148" /></div> </div> </body> </html> 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.