davidf85 Posted September 2, 2011 Share Posted September 2, 2011 I am using this code to build a form: echo '<form method="post" action="mysql.php">'; echo '<table>'; echo '<tr><td>UserID:</td>'; echo '<td><input type="text" name="username"></td></tr>'; echo '<tr><td>Password:</td>'; echo '<td><input type="password" name="password"></td></tr>'; echo '<tr><td colspan="2" align="center">'; echo '<input type="submit" value="Log In"></td></tr>'; echo '</table></form>'; Alone, this form works, but when I add script above it to make it more functional, everything loads properly and I get no errors, but the form will not submit. The submit button is like a dead button. Anyone know why this could be happening? Quote Link to comment https://forums.phpfreaks.com/topic/246262-form-not-working/ Share on other sites More sharing options...
AyKay47 Posted September 2, 2011 Share Posted September 2, 2011 1. you will want to add the name attribute to the submit button which will allow you to check for it being set. 2. can you post the "additional script" that you are referring to Quote Link to comment https://forums.phpfreaks.com/topic/246262-form-not-working/#findComment-1264666 Share on other sites More sharing options...
davidf85 Posted September 2, 2011 Author Share Posted September 2, 2011 <?php session_start(); if (isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; $link = mysql_connect('localhost', 'root', 'root', 'users'); if (!$link) { die("Cannot Connect".mysql_error()); } $query = "select * from users where username='$username' and password=sha1('$password')"; $result = mysql_query($query); if ($result->num_rows) { $_SESSION['valid_user'] = $username; } $link->close(); } ?> <html> <body> <?php if (isset($_SESSION['valid_user'])) { echo 'You are logged in as: '.$_Session['valid_user'].' <br>'; echo '<a href="logout.php">Log out</a><br>'; } else { if (isset($username)) { echo 'Could not log you in.<br>'; } else { echo 'You are not logged in.<br.'; } echo '<form method="post" action="mysql.php">'; echo '<table>'; echo '<tr><td>UserID:</td>'; echo '<td><input type="text" name="username"></td></tr>'; echo '<tr><td>Password:</td>'; echo '<td><input type="password" name="password"></td></tr>'; echo '<tr><td colspan="2" align="center">'; echo '<input type="submit" name=submit value="Log In"></td></tr>'; echo '</table></form>'; } ?> <a href="members_only.php">Members Section</a> </body> </html> MOD EDIT: code tags added. Quote Link to comment https://forums.phpfreaks.com/topic/246262-form-not-working/#findComment-1264701 Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2011 Share Posted September 2, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Variable names are case sensitive. echo 'You are logged in as: '.$_Session['valid_user'].' <br>'; // <---- $_SESSION, not $_Session Quote Link to comment https://forums.phpfreaks.com/topic/246262-form-not-working/#findComment-1264704 Share on other sites More sharing options...
AyKay47 Posted September 2, 2011 Share Posted September 2, 2011 I like to get into the habit of setting variables with indices into alternative variables to avoid syntax errors, and for the overall appeal of the code.. something like $valid_user = $_SESSION['valid_user'];//proceed using $valid_user Quote Link to comment https://forums.phpfreaks.com/topic/246262-form-not-working/#findComment-1264716 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.