Dench Posted February 18, 2008 Share Posted February 18, 2008 <? 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 More sharing options...
PFMaBiSmAd Posted February 18, 2008 Share Posted February 18, 2008 Your code is using short open tags - <? Use the full <?php opening tag. Link to comment https://forums.phpfreaks.com/topic/91722-logins-with-mysql/#findComment-469789 Share on other sites More sharing options...
Dench Posted February 18, 2008 Author Share Posted February 18, 2008 I have tried this but receive: Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\Program Files\EasyPHP 2.0b1\www\OurDatabase\login.php on line 14 instead, would it be easier to work around this error?? Link to comment https://forums.phpfreaks.com/topic/91722-logins-with-mysql/#findComment-469792 Share on other sites More sharing options...
rlindauer Posted February 18, 2008 Share Posted February 18, 2008 <?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 More sharing options...
vicodin Posted February 19, 2008 Share Posted February 19, 2008 <?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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.