dennismonsewicz Posted January 2, 2009 Share Posted January 2, 2009 I have the following login script: <?php require "includes/sql.php"; $action = $_GET['action']; $error = $_GET['error']; if($error) { $error = '<span style="color: red; display: block;">There was an error! Try again!</span>'; } if($_POST['username'] != '' || $_POST['password'] != '') { $_SESSION['username'] = stripslashes($_POST['username']); $_SESSION['password'] = stripslashes($_POST['password']); } else { header("location:index.php?error=yes"); } switch($action) { case "login": $result = mysql_query("SELECT * FROM users where username = '".mysql_real_escape_string($_SESSION['username'])."' AND password = '".mysql_real_escape_string($_SESSION['password'])."'") or die(mysql_error()); $num_rows = mysql_num_rows($result); header("location:index.php"); break; case "logout": session_destroy(); ob_end_flush(); header("location:index.php"); break; } $query = mysql_query("SELECT * FROM devotionals"); while($results = mysql_fetch_array($query)) { $writer = $results['writer']; $publish = $results['publish']; if($publish == 0) { $published = '<div class="publish-no">Not Approved!</div>'; } $devotional_query .= '<li><a href="devotional.php?action=view&id=' . $results['devotional_id'] . '&writer=' . $writer . '">' . ucwords(strtolower($results['devotional_title'])) . '</a>' . $published . '</li>'; } $login = '<a class="title">Login</a> <div> <form action="index.php?action=login" method="post"> <label>Username:</label> <input type="text" name="username" id="username" /> <label>Password: </label> <input type="password" name="password" id="password" /> <input type="image" src="images/login.jpg" id="submit" name="submit" /> </form> </div>'; $logout = '<a class="title">My Profile</a> <div> <ul> <li><a href="index.php">Home</a></li> <li><a href="profile.php?tool=changepw">Change Password</a></li> <li><a href="index.php?action=logout">Logout</a></li> </ul> </div> <a class="title">Tools</a> <div> <ul> <li><a href="devotional.php?action=create">Create a Devotional</a></li> <li><a href="devotional.php?action=edit_list">Edit a Devotional</a></li> <li><a href="profile.php?tool=addfriend">Signup A Friend</a></li> <li><a href="email.php?action=emailafriend">Email A Friend</a></li> </ul> </div> <a class="title">Devotionals</a> <div> <ul> ' . $devotional_query . ' </ul> </div> <a class="title">Topics</a> <div> <ul> <li><a href="submit.php?action=addtopic">Submit a Topic</a></li> </ul> </div>'; ?> <div class="accordion"> <?php if(!$_SESSION) { echo $login; echo $error; } else { echo $logout; } ?> </div> <!-- CLOSES ACCORDION DIV --> the problem is, is that a session is created no matter if a user inputs a password or not... even if the user puts in a username that isn't in the DB a session starts... any ideas? Session_start(); is on the header.php file. the above script is an include called accordion.php Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/ Share on other sites More sharing options...
flyhoney Posted January 2, 2009 Share Posted January 2, 2009 That's how it is supposed to work. Sessions exist for every person that visits your site. Sessions allow you to create user authentication systems, they aren't themselves user authentication systems. Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-728309 Share on other sites More sharing options...
dennismonsewicz Posted January 2, 2009 Author Share Posted January 2, 2009 hmmm alright... i re-read my original question/problem and it didn't come out right lol... been a long day... let me update the code i am missing with: <?php require "includes/sql.php"; $action = $_GET['action']; $error = $_GET['error']; if($error) { $error = '<span style="color: red; display: block; font-size: 11px; padding: 5px; font-weight: bold">There was an error!</span>'; } switch($action) { case "login": if(isset($_POST['submit'])) { if($_POST['username'] != '' || $_POST['password'] != '') { $_SESSION['username'] = stripslashes($_POST['username']); $_SESSION['password'] = stripslashes($_POST['password']); } } $result = mysql_query("SELECT * FROM users where username = '".mysql_real_escape_string($_SESSION['username'])."' AND password = '".mysql_real_escape_string($_SESSION['password'])."'") or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows > 0) { header("location:index.php"); } else { header("location:index.php?error=yes&numrows=" . $num_rows . ""); } break; case "logout": session_destroy(); ob_end_flush(); header("location:index.php"); break; } $query = mysql_query("SELECT * FROM devotionals"); while($results = mysql_fetch_array($query)) { $writer = $results['writer']; $publish = $results['publish']; if($publish == 0) { $published = '<div class="publish-no">Not Approved!</div>'; } $devotional_query .= '<li><a href="devotional.php?action=view&id=' . $results['devotional_id'] . '&writer=' . $writer . '">' . ucwords(strtolower($results['devotional_title'])) . '</a>' . $published . '</li>'; } $login = '<a class="title">Login</a> <div> <form action="index.php?action=login" method="post"> ' . $error . ' ' . $num_rows . ' <label>Username:</label> <input type="text" name="username" id="username" /> <label>Password: </label> <input type="password" name="password" id="password" /> <input type="image" src="images/login.jpg" id="submit" name="submit" /> </form> </div>'; $logout = '<a class="title">My Profile</a> <div> <ul> <li><a href="index.php">Home</a></li> <li><a href="profile.php?tool=changepw">Change Password</a></li> <li><a href="index.php?action=logout">Logout</a></li> </ul> </div> <a class="title">Tools</a> <div> <ul> <li><a href="devotional.php?action=create">Create a Devotional</a></li> <li><a href="devotional.php?action=edit_list">Edit a Devotional</a></li> <li><a href="profile.php?tool=addfriend">Signup A Friend</a></li> <li><a href="email.php?action=emailafriend">Email A Friend</a></li> </ul> </div> <a class="title">Devotionals</a> <div> <ul> ' . $devotional_query . ' </ul> </div> <a class="title">Topics</a> <div> <ul> <li><a href="submit.php?action=addtopic">Submit a Topic</a></li> </ul> </div>'; ?> <div class="accordion"> <?php if(!$_SESSION) { echo $login; } else { echo $logout; } ?> </div> <!-- CLOSES ACCORDION DIV --> I am passing the $num_rows var into the URL and it is passing 0... which i am not sure why it would be cause the user names i am using exist in the DB. Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-728312 Share on other sites More sharing options...
flyhoney Posted January 2, 2009 Share Posted January 2, 2009 Are you sure the passwords aren't hashed in the database? Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-728319 Share on other sites More sharing options...
dennismonsewicz Posted January 2, 2009 Author Share Posted January 2, 2009 they aren't for debugging purposes... ok so i shortened my SQL command to this: $result = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($_SESSION['username'])."'") or die(mysql_error()); And it works even if the user doesn't add type anything in the password field. Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-728326 Share on other sites More sharing options...
revraz Posted January 2, 2009 Share Posted January 2, 2009 So what is your question exactly? A session will start if you use session_start. Maybe you should set a specific session variable after they login? Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-728373 Share on other sites More sharing options...
dennismonsewicz Posted January 5, 2009 Author Share Posted January 5, 2009 I have updated my code: <?php require "includes/sql.php"; if(isset($_POST['submit'])) { if($_POST['username'] != '') { $_SESSION['username'] = stripslashes($_POST['username']); } else { $u_error = '<span style="color: red; display: block; font-size: 11px; padding: 5px; font-weight: bold">There was an error!</span>'; } if($_POST['password'] != '') { $_SESSION['password'] = stripslashes($_POST['password']); } else { $p_error = '<span style="color: red; display: block; font-size: 11px; padding: 5px; font-weight: bold">There was an error!</span>'; } $qry = mysql_query("SELECT * FROM users WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "' AND password = '" . mysql_real_escape_string($_SESSION['password']) . "'")or die(mysql_error()); if($qry) { $query = mysql_query("SELECT * FROM devotionals")or die(mysql_error()); while($results = mysql_fetch_object($query)) { $writer = $results->writer; $publish = $results->publish; if($publish == 0) { $published = '<div class="publish-no">Not Approved!</div>'; } $devotional_query .= '<li><a href="devotional.php?action=view&id=' . $results->devotional_id . '&writer=' . $writer . '">' . ucwords(strtolower($results->devotional_title)) . '</a>' . $published . '</li>'; } echo '<a class="title">My Profile</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="index.php">Home</a></li>'; echo '<li><a href="profile.php?tool=changepw">Change Password</a></li>'; echo '<li><a href="index.php?action=logout">Logout</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Tools</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="devotional.php?action=create">Create a Devotional</a></li>'; echo '<li><a href="devotional.php?action=edit_list">Edit a Devotional</a></li>'; echo '<li><a href="profile.php?tool=addfriend">Signup A Friend</a></li>'; echo '<li><a href="email.php?action=emailafriend">Email A Friend</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Devotionals</a>'; echo '<div>'; echo '<ul>'; echo $devotional_query; echo '</ul>'; echo '</div>'; echo '<a class="title">Topics</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="submit.php?action=addtopic">Submit a Topic</a></li>'; echo '</ul>'; echo '</div>'; } } else { echo '<div class="accordion">'; echo '<a class="title">Login</a>'; echo '<div>'; echo '<form action="index.php" method="post" name="login_form">'; echo '<label>Username:</label> <input type="text" name="username" id="username" />'; echo $u_error; echo '<label>Password: </label> <input type="password" name="password" id="password" />'; echo $p_error; echo '<input type="image" src="images/login.jpg" id="submit" name="submit" />'; echo '</form>'; echo '</div>'; echo '</div>'; //closes accordion div } ?> The page is not logging in and it just keeps showing the login form after clicking submit Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730045 Share on other sites More sharing options...
KevinM1 Posted January 5, 2009 Share Posted January 5, 2009 I don't understand why you're starting off with sessions. Do you really want to keep all login attempts as a session, even the failed ones? What you should do is: 1. Obtain the login input: session_start(); if(isset($_POST['submit'])) { if(!empty($_POST['username'])) { $tmpUsername = stripslashes($_POST['username']); } if(!empty($_POST['password'])) { $tmpPassword = stripslashes($_POST['password']); } 2. Then, check those values against what's in the database, and if the user attempting to login is legit, then you set the session variable: $query = "SELECT * FROM users WHERE username = '" . mysql_real_escape_string($tmpUsername) . "' AND password = '" . mysql_real_escape_string($tmpPassword) . "'"; $result = mysql_query($query) or die(mysql_error()); if(result && mysql_num_rows == 1) //just to double-check against duplicate entries { $_SESSION['username'] = $tmpUsername; } You don't want to store a user's password in a session. Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730062 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 I would change this: if($qry) { to if(mysql_num_rows($qry) > 0) { Then here: echo '<input type="image" src="images/login.jpg" id="submit" name="submit" />'; Your submit button is of type "image", shouldn't this be "submit"...I am not sure on this, so yea... if you want it of type image, maybe try this: echo '<input type="image" src="images/login.jpg" id="submit" onClick="this.submit()" name="submit" />'; So it will actually submit the form onclick. That is why the form keeps displaying, it is never being submitted. Fix that and your form should submit. Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730065 Share on other sites More sharing options...
dennismonsewicz Posted January 5, 2009 Author Share Posted January 5, 2009 i tried both suggestions and still a big ol goose egg also the session is being started on the header.php file... the code below is in an included file called accordion.php updated code: <?php require "includes/sql.php"; if(isset($_POST['submit'])) { if(!empty($_POST['username'])) { $tmpUsername = stripslashes($_POST['username']); } if(!empty($_POST['password'])) { $tmpPassword = stripslashes($_POST['password']); } $login_ck_query = mysql_query("SELECT * FROM users WHERE username = '" . mysql_real_escape_string($tmpUsername) . "' AND password = '" . mysql_real_escape_string($tmpPassword) . "'")or die(mysql_error()); $num_rows = mysql_num_rows($query); if($login_ck_query && $num_rows == 1) { $_SESSION['username'] = $tmpUsername; $query = mysql_query("SELECT * FROM devotionals")or die(mysql_error()); while($results = mysql_fetch_object($query)) { $writer = $results->writer; $publish = $results->publish; if($publish == 0) { $published = '<div class="publish-no">Not Approved!</div>'; } $devotional_query .= '<li><a href="devotional.php?action=view&id=' . $results->devotional_id . '&writer=' . $writer . '">' . ucwords(strtolower($results->devotional_title)) . '</a>' . $published . '</li>'; } echo '<a class="title">My Profile</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="index.php">Home</a></li>'; echo '<li><a href="profile.php?tool=changepw">Change Password</a></li>'; echo '<li><a href="index.php?action=logout">Logout</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Tools</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="devotional.php?action=create">Create a Devotional</a></li>'; echo '<li><a href="devotional.php?action=edit_list">Edit a Devotional</a></li>'; echo '<li><a href="profile.php?tool=addfriend">Signup A Friend</a></li>'; echo '<li><a href="email.php?action=emailafriend">Email A Friend</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Devotionals</a>'; echo '<div>'; echo '<ul>'; echo $devotional_query; echo '</ul>'; echo '</div>'; echo '<a class="title">Topics</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="submit.php?action=addtopic">Submit a Topic</a></li>'; echo '</ul>'; echo '</div>'; } } else { echo '<div class="accordion">'; echo '<a class="title">Login</a>'; echo '<div>'; echo '<form action="index.php" method="post" name="login_form">'; echo '<label>Username:</label> <input type="text" name="username" id="username" />'; echo $u_error; echo '<label>Password: </label> <input type="password" name="password" id="password" />'; echo $p_error; echo '<input type="image" src="images/login.jpg" id="submit" onClick="this.submit()" name="submit" />'; echo '</form>'; echo '</div>'; echo '</div>'; //closes accordion div } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730071 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 echo '<input type="image" src="images/login.jpg" id="submit" onClick="document.forms.login_form.submit()" name="submit" />'; The javascript I gave you was bad, chances are you had a javascript error. Try using the above. Again this JS might also be bad, but that is the source of your issue, so yea. If it does not work again, google submitting form javascript onclick and look at their examples and try them. Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730075 Share on other sites More sharing options...
KevinM1 Posted January 5, 2009 Share Posted January 5, 2009 If you're using JavaScript to submit the form, why not do it the unobtrusive, and less headache-inducing, way like so: <html> <head> <title>Login</title> <script type="text/javascript"> window.onload = function() { var imageSubmit = document.getElementById('imageSubmit'); imageSubmit.onclick = function() { document.forms['login_form'].submit(); } } </script> </head> <!-- code up until the actual image that's used as the submit --> <?php echo '<input type="image" src="images/login.png" id="imageSubmit" name="submit" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730081 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 If you're using JavaScript to submit the form, why not do it the unobtrusive, and less headache-inducing, way like so: <html> <head> <title>Login</title> <script type="text/javascript"> window.onload = function() { var imageSubmit = document.getElementById('imageSubmit'); imageSubmit.onclick = function() { document.forms['login_form'].submit(); } } </script> </head> <!-- code up until the actual image that's used as the submit --> <?php echo '<input type="image" src="images/login.png" id="imageSubmit" name="submit" />'; ?> lol I fail to see how that is less of a headache...more code = more chance to mess up = larger headache??? But it probably works, so yea. To each their own. EDIT: But it brings up a good point, you could use this instead lol. echo '<input type="image" src="images/login.jpg" id="submit" onClick="document.forms[\'login_form\'].submit()" name="submit" />'; Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730084 Share on other sites More sharing options...
dennismonsewicz Posted January 5, 2009 Author Share Posted January 5, 2009 I do not know why is this is not working... i tried the examples and get nothing Any other ideas? I even took off the type="image" and replaced it with type="submit" and that works Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730092 Share on other sites More sharing options...
KevinM1 Posted January 5, 2009 Share Posted January 5, 2009 If you're using JavaScript to submit the form, why not do it the unobtrusive, and less headache-inducing, way like so: <html> <head> <title>Login</title> <script type="text/javascript"> window.onload = function() { var imageSubmit = document.getElementById('imageSubmit'); imageSubmit.onclick = function() { document.forms['login_form'].submit(); } } </script> </head> <!-- code up until the actual image that's used as the submit --> <?php echo '<input type="image" src="images/login.png" id="imageSubmit" name="submit" />'; ?> lol I fail to see how that is less of a headache...more code = more chance to mess up = larger headache??? But it probably works, so yea. To each their own. Slightly more code, which is, IMO more readable, that's separated from the markup entirely. Much like how it's generally accepted that HTML and CSS should be separate, the same goes for HTML and JavaScript. By compartmentalizing each tier of a web app, you encapsulate functionality, thereby reducing bugs and making it easier to squash the ones that do crop up. In other words, instead of the OP having to search through lines of code for that one magic echo statement that contains the JavaScript which submits the form, it's all in the head element, where it should be (if not in an external file). But, this is an argument for another time. If you're interested in why I find this method of coding JavaScript to be preferable to other methods that mix and match script code with markup, then you should look at some of the trainwrecks that get posted in the JavaScript section of the board. Yeesh. EDIT: I do not know why is this is not working... i tried the examples and get nothing Any other ideas? I even took off the type="image" and replaced it with type="submit" and that works Mind posting the code of your latest attempt? Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730095 Share on other sites More sharing options...
dennismonsewicz Posted January 5, 2009 Author Share Posted January 5, 2009 latest code: <?php require "includes/sql.php"; if(isset($_POST['login_form'])) { if(!empty($_POST['username'])) { $tmpUsername = stripslashes($_POST['username']); } if(!empty($_POST['password'])) { $tmpPassword = stripslashes($_POST['password']); } $login_ck_query = mysql_query("SELECT * FROM users WHERE username = '" . mysql_real_escape_string($tmpUsername) . "' AND password = '" . mysql_real_escape_string($tmpPassword) . "'")or die(mysql_error()); $num_rows = mysql_num_rows($login_ck_query); if($login_ck_query && $num_rows == 1) { $_SESSION['username'] = $tmpUsername; $query = mysql_query("SELECT * FROM devotionals")or die(mysql_error()); while($results = mysql_fetch_object($query)) { $writer = $results->writer; $publish = $results->publish; if($publish == 0) { $published = '<div class="publish-no">Not Approved!</div>'; } $devotional_query .= '<li><a href="devotional.php?action=view&id=' . $results->devotional_id . '&writer=' . $writer . '">' . ucwords(strtolower($results->devotional_title)) . '</a>' . $published . '</li>'; } echo '<div class="accordion">'; echo '<a class="title">My Profile</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="index.php">Home</a></li>'; echo '<li><a href="profile.php?tool=changepw">Change Password</a></li>'; echo '<li><a href="index.php?action=logout">Logout</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Tools</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="devotional.php?action=create">Create a Devotional</a></li>'; echo '<li><a href="devotional.php?action=edit_list">Edit a Devotional</a></li>'; echo '<li><a href="profile.php?tool=addfriend">Signup A Friend</a></li>'; echo '<li><a href="email.php?action=emailafriend">Email A Friend</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Devotionals</a>'; echo '<div>'; echo '<ul>'; echo $devotional_query; echo '</ul>'; echo '</div>'; echo '<a class="title">Topics</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="submit.php?action=addtopic">Submit a Topic</a></li>'; echo '</ul>'; echo '</div>'; echo '</div>'; //div closes accordion div } } else { echo '<div class="accordion">'; echo '<a class="title">Login</a>'; echo '<div>'; echo '<form action="index.php" method="post" name="login_form">'; echo '<label>Username:</label> <input type="text" name="username" id="username" />'; echo $u_error; echo '<label>Password: </label> <input type="password" name="password" id="password" />'; echo $p_error; echo '<input type="image" src="images/login.jpg" id="submit" onClick="document.forms[\'login_form\'].submit()" name="submit" />'; echo '</form>'; echo '</div>'; echo '</div>'; //closes accordion div } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730096 Share on other sites More sharing options...
KevinM1 Posted January 5, 2009 Share Posted January 5, 2009 latest code: <?php require "includes/sql.php"; if(isset($_POST['login_form'])) { if(!empty($_POST['username'])) { $tmpUsername = stripslashes($_POST['username']); } if(!empty($_POST['password'])) { $tmpPassword = stripslashes($_POST['password']); } $login_ck_query = mysql_query("SELECT * FROM users WHERE username = '" . mysql_real_escape_string($tmpUsername) . "' AND password = '" . mysql_real_escape_string($tmpPassword) . "'")or die(mysql_error()); $num_rows = mysql_num_rows($login_ck_query); if($login_ck_query && $num_rows == 1) { $_SESSION['username'] = $tmpUsername; $query = mysql_query("SELECT * FROM devotionals")or die(mysql_error()); while($results = mysql_fetch_object($query)) { $writer = $results->writer; $publish = $results->publish; if($publish == 0) { $published = '<div class="publish-no">Not Approved!</div>'; } $devotional_query .= '<li><a href="devotional.php?action=view&id=' . $results->devotional_id . '&writer=' . $writer . '">' . ucwords(strtolower($results->devotional_title)) . '</a>' . $published . '</li>'; } echo '<div class="accordion">'; echo '<a class="title">My Profile</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="index.php">Home</a></li>'; echo '<li><a href="profile.php?tool=changepw">Change Password</a></li>'; echo '<li><a href="index.php?action=logout">Logout</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Tools</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="devotional.php?action=create">Create a Devotional</a></li>'; echo '<li><a href="devotional.php?action=edit_list">Edit a Devotional</a></li>'; echo '<li><a href="profile.php?tool=addfriend">Signup A Friend</a></li>'; echo '<li><a href="email.php?action=emailafriend">Email A Friend</a></li>'; echo '</ul>'; echo '</div>'; echo '<a class="title">Devotionals</a>'; echo '<div>'; echo '<ul>'; echo $devotional_query; echo '</ul>'; echo '</div>'; echo '<a class="title">Topics</a>'; echo '<div>'; echo '<ul>'; echo '<li><a href="submit.php?action=addtopic">Submit a Topic</a></li>'; echo '</ul>'; echo '</div>'; echo '</div>'; //div closes accordion div } } else { echo '<div class="accordion">'; echo '<a class="title">Login</a>'; echo '<div>'; echo '<form action="index.php" method="post" name="login_form">'; echo '<label>Username:</label> <input type="text" name="username" id="username" />'; echo $u_error; echo '<label>Password: </label> <input type="password" name="password" id="password" />'; echo $p_error; echo '<input type="image" src="images/login.jpg" id="submit" onClick="document.forms[\'login_form\'].submit()" name="submit" />'; echo '</form>'; echo '</div>'; echo '</div>'; //closes accordion div } ?> Well, your major problem is this line: if(isset($_POST['login_form'])) { You don't check against the form name. Instead, you check against the name of the input that actually submits the form, which, in this case, would be the image input named 'submit.' In other words: if(isset($_POST['submit'])){ Also, you shouldn't need any JavaScript for an image input to submit a form. They should do it automatically, according to the HTML form spec: http://www.w3.org/TR/html401/interact/forms.html#h-17.4.1 Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730099 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 But, this is an argument for another time. If you're interested in why I find this method of coding JavaScript to be preferable to other methods that mix and match script code with markup, then you should look at some of the trainwrecks that get posted in the JavaScript section of the board. Yeesh. There ya go, I do not look at the javascript section, I am sure if I did I would have a different take. Either way thanks for writing out your explanation =) Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730102 Share on other sites More sharing options...
dennismonsewicz Posted January 5, 2009 Author Share Posted January 5, 2009 Thanks for all of the help thus far.. i was unable to submit the form with the latest suggestions i do not know why this is not working... i have done this in the past with no problem! Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730114 Share on other sites More sharing options...
dennismonsewicz Posted January 5, 2009 Author Share Posted January 5, 2009 fixed it! Gotta love CSS Here is the HTML rendered code: <input type="submit" id="submit" name="login_submit" value="" /> and the CSS to style it #submit { float: right; margin-right: 5px; padding-bottom: 5px; background: url(path_to_image) no-repeat left top; width: 72px; height: 33px; border: 0px; } Quote Link to comment https://forums.phpfreaks.com/topic/139237-solved-login-system-troubles/#findComment-730170 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.