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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.