Jump to content

How to specifiy 2 varaible's for login php using mysql


natsu

Recommended Posts

Ok so I need to create a form to accept the users EmailAddress and Password as credentials to your site then use an SQL Query to determine if the person has an account

 

<?php

require "connectionInfo.php";

$error = "";

if(!isset($_POST["personId"]) || !isset($_POST["firstName"]) || !isset($_POST["lastName"]) || !isset($_POST["emailAddress"]) || !isset($_POST["telephoneNumber"]) || !isset($_POST["socialInsuranceNumber"]) || !isset($_POST["password"])  )
{
$error = "Please fill in the info";
}
else
{
if($_POST["personId"] != "" && $_POST["firstName"] != "" && $_POST["lastName"] != "" && $_POST["emailAddress"] != "" && $_POST["telephoneNumber"] != "" &&$_POST["socialInsuranceNumber"] != ""  && $_POST["password"] != "")
{		
	$dbConnection = mysql_connect($host, $username, $password);

	if(!$dbConnection)
	die("Could not connect to the database. Remember this will only run on the Playdoh server.");

	mysql_select_db($database);

	$sqlQuery = "INSERT INTO persons (personId, FirstName, LastName, emailAddress, telephoneNumber, socialInsuranceNumber, password) VALUES('".$_POST["personId"]."', '".$_POST["firstName"]."', '".$_POST["lastName"]."', '".$_POST["emailAddress"]."', '".$_POST["telephoneNumber"]."', '".$_POST["socialInsuranceNumber"]."', '".$_POST["password"]."')";

		if(mysql_query($sqlQuery))
	$error = "Person Successfully Added";
		else
	$error = "Person Could not be added ".mysql_error();

	mysql_close($dbConnection);
}
else	
	$error = "Please enter all the information";	
}

?>

			<form action="createAccount.php" method="post">
				Person ID: <input type="text" name="personId" />
				<br />
				First Name: <input type="text" name="firstName" />
				<br />
				Last Name: <input type="text" name="lastName" />
				<br />
				Email: <input type="text" name="emailAddress" />
				<br />
				Telephone: <input type="text" name="telephoneNumber" />
				<br />
				Social Insurance Number: <input type="text" name="socialInsuranceNumber" />
				<br />
				Password: <input type="text" name="password" />
				<br />
				<input type="submit" value="Submit to Database" />
			</form>

 

-----EDIT-----

 

Ok I was able to create the html code for it, but how do I use an sql query to determine if the person has an account?

 

<form method='post' action='login.php'>
					<table><tr><td>Email Address:</td><td><input type='text' name='emailAddress'></td></tr>
				<tr><td>Password:</td><td><input type='password' name='password'></td></tr>
				<tr><td></td><td><input type='submit' name='submit' value='Log in'></td></tr></table>
			</form>

This is what I got so far

 

<?php

require "connectionInfo.php";

$dbConnection = mysql_connect($host, $username, $password);

if(!$dbConnection)
die("Could not connect to the database. Remember this will only run on the Playdoh server.");

mysql_select_db($lab9_hadd0076);

$sqlQuery = "SELECT * FROM persons";

$result = mysql_query($sqlQuery);

//$loginDetail = emailAddress, password; How do I specify the login credentials, I know this is wrong 

if($loginDetail == 0)
echo "*** There is no accounts made ***";
else {
	echo "Yes you have created an account";

}

mysql_close($dbConnection);

?>

<?php

require "connectionInfo.php";

$dbConnection = mysql_connect($host, $username, $password);

if(!$dbConnection)
die("Could not connect to the database. Remember this will only run on the Playdoh server.");

mysql_select_db($lab9_hadd0076);

$login = $_POST['whatever name your form login field has']; 
$pwd = $_POST['whatever name your form login field has']; 

$sqlQuery = "SELECT * FROM persons WHERE userName= '$login' AND password = '$pwd'";

$result = mysql_query($sqlQuery);

if(mysql_num_rows($result) == 0)
echo "There is no user with these credentials";
}else{
$user = mysql_fetch_array($result);
echo "Welcome, " . $user['userName'];
}

mysql_close($dbConnection);

?>

Yes then it would be:

 

<?php

require "connectionInfo.php";

$dbConnection = mysql_connect($host, $username, $password);

if(!$dbConnection)
die("Could not connect to the database. Remember this will only run on the Playdoh server.");

mysql_select_db($lab9_hadd0076);

$email = $_POST['emailAddress']; 
$pwd = $_POST['password'];

// if your columnnames are different, change it
$sqlQuery = "SELECT * FROM persons WHERE emailAddress = '$email' AND password = '$pwd'";

$result = mysql_query($sqlQuery);

if(mysql_num_rows($result) == 0)
echo "There is no user with these credentials";
}else{
$user = mysql_fetch_array($result);
// between the brackets is a columnname (so if it's different, change it)
echo "Welcome, " . $user['userName'];
}

mysql_close($dbConnection);

?>

It's still not working :P

 

Here is the HTML on the same page (in first post too)

			<form method='post' action='login.php'>
					<table><tr><td>Email Address:</td><td><input type='text' name='emailAddress'></td></tr>
				<tr><td>Password:</td><td><input type='password' name='password'></td></tr>
				<tr><td></td><td><input type='submit' name='submit' value='Log in'></td></tr></table>
			</form>

 

The emailAddress and password was made using this on my createAccounte.php

 

			<?php

			require "connectionInfo.php";

			$error = "";

			if(!isset($_POST["personId"]) || !isset($_POST["firstName"]) || !isset($_POST["lastName"]) || !isset($_POST["emailAddress"]) || !isset($_POST["telephoneNumber"]) || !isset($_POST["socialInsuranceNumber"]) || !isset($_POST["password"])  )
			{
				$error = "Please fill in the info";
			}
			else
			{
				if($_POST["personId"] != "" && $_POST["firstName"] != "" && $_POST["lastName"] != "" && $_POST["emailAddress"] != "" && $_POST["telephoneNumber"] != "" && $_POST["socialInsuranceNumber"] != ""  && $_POST["password"] != "")
				{		
					$dbConnection = mysql_connect($host, $username, $password);

					if(!$dbConnection)
					die("Could not connect to the database. Remember this will only run on the Playdoh server.");

					mysql_select_db($database);

					$sqlQuery = "INSERT INTO persons (FirstName, LastName, EmailAddress, TelephoneNumber, SocialInsuranceNumber, Password) VALUES('".$_POST["firstName"]."', '".$_POST["lastName"]."', '".$_POST["emailAddress"]."', '".$_POST["telephoneNumber"]."', '".$_POST["socialInsuranceNumber"]."', '".$_POST["password"]."');";

					if(mysql_query($sqlQuery))
						$error = "Person Successfully Added";
					else
						$error = "Person Could not be added : ".mysql_error();

					mysql_close($dbConnection);
				}
				else	
					$error = "Please enter all the information";	
			}

			?>
			<form action="createAccount.php" method="post">
				Person ID: <input type="text" name="personId" />
				<br />
				First Name: <input type="text" name="firstName" />
				<br />
				Last Name: <input type="text" name="lastName" />
				<br />
				Email: <input type="text" name="emailAddress" />
				<br />
				Telephone: <input type="text" name="telephoneNumber" />
				<br />
				Social Insurance Number: <input type="text" name="socialInsuranceNumber" />
				<br />
				Password: <input type="text" name="password" />
				<br />
				<input type="submit" value="Submit to Database" />
			</form>
			<br />
			<br />
			<?php echo $error; ?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.