Jump to content

Logins with MySQL!!


Dench

Recommended Posts

<?
require("db.inc.php");

if(! empty($_POST['UserName']) && ! empty($_POST['Password']))
{
$UserName = mysql_real_escape_string($_POST['UserName']);
$PassWord = mysql_real_escape_string($_POST['Password']);

$sql = "SELECT UserName FROM login_table WHERE UserName = '{$UserName}' AND Password = '{$Password}'";
$query = mysql_query($sql);

if(mysql_num_rows($query) == 1)
{
	echo "You have been sucessfully logged in! <br><br> <a href="result.php">Continue...</a>";
}
else
{
	echo "Your login failed. =( <br><br> <a href="index.html">Go back...</a>";
}
}
else
{
die("You did not enter a name and email address");
}
?>

 

Now, i implemented this in easyPHP, and tested the login and i receive the following output:

 

Continue... "; } else { echo "Your login failed. =(

 

Go back..."; } } else { die("You did not enter a name and email address"); } ?>

 

I am confused as to why part of my code has simply been regurgitated back to me, i have played with the syntax but cannot solve this problem please help!!

Link to comment
https://forums.phpfreaks.com/topic/91722-logins-with-mysql/
Share on other sites

<?php
require("db.inc.php");

if(! empty($_POST['UserName']) && ! empty($_POST['Password']))
{
$UserName = mysql_real_escape_string($_POST['UserName']);
$PassWord = mysql_real_escape_string($_POST['Password']);

$sql = "SELECT UserName FROM login_table WHERE UserName = '{$UserName}' AND Password = '{$Password}'";
$query = mysql_query($sql);

if(mysql_num_rows($query) == 1)
{
	echo "You have been sucessfully logged in! <br><br> <a href="result.php">Continue...</a>";
}
else
{
	echo "Your login failed. =( <br><br> <a href="index.html">Go back...</a>";
}
}
else
{
die("You did not enter a name and email address");
}
?>

 

You have syntax errors. You have to escape your quotes in your echo statements.

Link to comment
https://forums.phpfreaks.com/topic/91722-logins-with-mysql/#findComment-469828
Share on other sites

<?php
require("db.inc.php");

if(! empty($_POST['UserName']) && ! empty($_POST['Password']))
{
$UserName = mysql_real_escape_string($_POST['UserName']);
$PassWord = mysql_real_escape_string($_POST['Password']);

$sql = "SELECT UserName FROM login_table WHERE UserName = '{$UserName}' AND Password = '{$Password}'";
$query = mysql_query($sql);

if(mysql_num_rows($query) == 1)
{
	echo "You have been sucessfully logged in! <br><br> <a href="result.php">Continue...</a>";
}
else
{
	echo "Your login failed. =( <br><br> <a href="index.html">Go back...</a>";
}
}
else
{
die("You did not enter a name and email address");
}
?>

Change it to:

<?php
require("db.inc.php");

if(! empty($_POST['UserName']) && ! empty($_POST['Password']))
{
$UserName = mysql_real_escape_string($_POST['UserName']);
$PassWord = mysql_real_escape_string($_POST['Password']);

$sql = "SELECT UserName FROM login_table WHERE UserName = '{$UserName}' AND Password = '{$Password}'";
$query = mysql_query($sql);

if(mysql_num_rows($query) == 1)
{
	echo 'You have been sucessfully logged in! <br><br> <a href="result.php">Continue...</a>';
}
else
{
	echo 'Your login failed. =( <br><br> <a href="index.html">Go back...</a>';
}
}
else
{
die("You did not enter a name and email address");
}
?>

 

You cant have " inside of a " ... You need to put a ' so it doesnt try to parse the inside "

Link to comment
https://forums.phpfreaks.com/topic/91722-logins-with-mysql/#findComment-470121
Share on other sites

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.