0

Yesterday, I had started a thread with a problem, am trying to execute the script below, but each time it is failing and returning "Unable to record form details".
Note: "Unable to record form details" is the response returned when isset($_POST) is not working, refer the code for more details.

That thread is solved and that part is still working, I followed the guidelines given therein, but the issue seems to be persisting.

The older thread:
http://www.daniweb.com/forums/thread312688.html

<form action="loggedIn.php" method="post" name="form">
			<table class="TableLogin" style="cellpadding:4px; cellspacing:2px;">
				
				<tr class="TableHeading">
					<td colspan="2">Login Here</td>
				</tr>
				
				<tr class="FormContents">
					<td>Username</td>
					<td><input type="text" id="usrName" name="getName" size="20px"  onkeyup="AJAX_Test(this.value)"/>
					</td>
				</tr>
				
				<tr class="FormContents">
					<td>Password</td>
					<td><input type="password" id="pWord" name="getPass" size="20px"/></td>
				</tr>
				
				<tr class="FormContents">
					<td></td>
					<td align="right"><input type="submit" name="bt" id="lgSubmit" value="Login" onclick="loginCheck()"/></td>
				</tr>
				
				<tr class="FormContents">
				<td align="center" colspan="2" id="lgLabel">Suggestions</td>
				</tr>
				
			</table>
			</form>
<?php
if((isset($_POST['getName'])) && (isset($_POST['getPass'])))
{
			
		$uName = $_POST["getName"];
		$pWord = $_POST["getPass"];
			
		$con = mysql_connect("","root","");
		if(!$con)
		{
			die("Unable to connect to the SQL Server. ");
		}

		$sql_db = mysql_select_db("learn", $con);
		if(!$sql_db)
		{
			die("Unable to select the database. ");
		}

		//Core Login Script
		$sql="SELECT * FROM loginrecords WHERE username='$uName' and password='$pWord'";
		$result = mysql_query($sql);

		// Mysql_num_row is counting table row
		$count=mysql_num_rows($result);
		// If result matched $uName and $pWord, table row must be 1 row

		if($count==1)
		{
				// Register $uName, $pWord and redirect to file "login_success.php"
				session_register("uName");
				session_register("pWord"); 
				header("location:loggedIn.php");
				echo "Welcome " . $uName;
		}
		else 
		{
				echo "Wrong Username or Password. <br/>";
		}
}
		
else
{
		$test=0;
		die ("Unable to record form details. <br/>");
}

?>
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by iammirko
0

Try creating a seperate page to see if the variables are being passed after validating.

<?php
if(isset($_POST['submit'])) {
    echo $_POST['getName'];
    echo $_POST['getPass'];
}
?>

If they are, try this code.
I think i know what login script your using. If you want, this is the one that i was using..

checklogin.php

<?php
$host = "";
$username = "root";
$password = "";
$db_name = "";

mysql_connect("$host", "$username", "$password") or die("Couldnt Connect");
mysql_select_db("$db_name") or die("Couldnt select db");

$username = $_POST['getName'];
$password = $_POST['getPass'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql = "SELECT * FROM table WHERE username = '$username' and password = '$password'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);

if($count==1) {
    session_register("username");
    session_register("password");
    header("location:page.html"); // go here if login successful
} else { 
    header("location:wrong.html"); // go here if login failed
}
?>

let me know if this worked..

0

I did not change the script. I rather deleted the HTML file and rewrote it. Working now!

BTW, Thanks for suggesting. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.