Hi, every time somebody fixes my login code, for some reason it just errors, or doesnt work? I have no idea why but everything just goes wrong for me?
giving me a syntax error, unexpected T_STRING line 10
heres the code :
<?php>
$username = $POST['username'];
$password = $POST['password'];
$id = $POST['id'];
if($username&&$password&&$id) {
$con = mysql_connect('********************************', '************', '*********');
$sql = mysql_query(SELECT users.username, users.password, users.id FROM users WHERE username= '$username' AND password= '$password' AND id= '$id');
}
if($sql['id'] < 1) {
instert('back-index-button.php');
instert('back-home-button.php');
print('Username, Password or ID is wrong. Go back and try again! If you are not an admin, please vactate this page');
}
if($sql['id'] > 0) {
instert('continue.php');
print('Logged in, press continue to connect to the database!');
}
else {
print('Please fill in the required loggin feilds!');
}
</php>
Thanks
You shouldn't need to post on forums to ask about syntax errors. Google the syntax error you are getting and look at line 10 to figure out what is causing the syntax error. You'll gain so much more by learning to figure these kinds of little things out for yourself than by asking other people how to fix them. Especially basic things like syntax problems since learning those means you're [B]really[/B] learning to understand the language and how it works.
Not trying to be a cock by telling you to just google it, just trying to get you in a mindset that will be infinitely more helpful if you want to continue to learn development.
iv tryed google but I cant seem to find a solution
[QUOTE=xXMangoFaceXx;32093020]
<?php>
... Code with missing quotes
</php>
[/QUOTE]
Why are you closing the php tags... like if they were HTML?
php tags should be <?php (your php code) ?>
[QUOTE=commander204;32095472]Why are you closing the php tags... like if they were HTML?[/QUOTE]
the funny part is he starts it with ?php but doesnt end with ?php
You really should stop for a second.
You're obviously learning, cool, mistakes happen; but you're going too fast for your own good. You're messing around with database connections and what are usually mildly complex operations without a [B]basic[/B] grasp of the PHP syntax.
Myself and others can give you a hand, but first answer me this - where are you learning PHP from?
[B]PS:[/B] stop making thread about this, one's enough.
Here you go buddy,
[php]
<?php
if(isset($_POST)){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$password = $password; // encrypt that shit here, bitch. (md5, sha, etc)
$checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
if(mysql_num_rows($checklogin) == 1){
$checkPass = mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."' ");
if(mysql_num_rows($checkPass) == 1){
$User = mysql_fetch_array($checkPass);
echo "Hello ". $User["username"]."! How are you?";
// LOGGED IN STUFF HERE FAG
}else{
echo "Hey Faggot homo you entered the wrong fucking password";
}
}else{
echo "Hey faggot bitch that user doesn't fucking exist.";
}
}
?>
[/php]
I made it in 5 minutes, and I tried to make it as simple and understandable as possible, you NEED to look up (and understand) the use of sessions. Also you need to try to learn the language from the ground up, not just start at something you want done, don't just have functional code that someone else gave you, have code you understand and can improve later.
[QUOTE=nivek;32108221]Here you go buddy,
[php]
<?php
if(isset($_POST)){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$password = $password; // encrypt that shit here, bitch. (md5, sha, etc)
$checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
if(mysql_num_rows($checklogin) == 1){
$checkPass = mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."' ");
if(mysql_num_rows($checkPass) == 1){
$User = mysql_fetch_array($checkPass);
echo "Hello ". $User["username"]."! How are you?";
// LOGGED IN STUFF HERE FAG
}else{
echo "Hey Faggot homo you entered the wrong fucking password";
}
}else{
echo "Hey faggot bitch that user doesn't fucking exist.";
}
}
?>
[/php]
I made it in 5 minutes, and I tried to make it as simple and understandable as possible, you NEED to look up (and understand) the use of sessions. Also you need to try to learn the language from the ground up, not just start at something you want done, don't just have functional code that someone else gave you, have code you understand and can improve later.[/QUOTE]
Why do two SQL queries? You could just look for the user in the database, fetch the password of one row if it finds any, and then check if the passwords match in the php code instead.
[QUOTE=nivek;32108221]Here you go buddy,
[php]
<?php
if(isset($_POST)){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$password = $password; // encrypt that shit here, bitch. (md5, sha, etc)
$checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
if(mysql_num_rows($checklogin) == 1){
$checkPass = mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."' ");
if(mysql_num_rows($checkPass) == 1){
$User = mysql_fetch_array($checkPass);
echo "Hello ". $User["username"]."! How are you?";
// LOGGED IN STUFF HERE FAG
}else{
echo "Hey Faggot homo you entered the wrong fucking password";
}
}else{
echo "Hey faggot bitch that user doesn't fucking exist.";
}
}
?>
[/php]
I made it in 5 minutes, and I tried to make it as simple and understandable as possible, you NEED to look up (and understand) the use of sessions. Also you need to try to learn the language from the ground up, not just start at something you want done, don't just have functional code that someone else gave you, have code you understand and can improve later.[/QUOTE]
You can even optimize the query!
[php]
<?php
if(isset($_POST)){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$password = $password; // encrypt that shit here, bitch. (md5, sha, etc)
$checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."' LIMIT 1");
if(mysql_num_rows($checklogin) == 1){
$result = mysql_fetch_array($checklogin);
if($result["password"] == $password){
$User = $result;
echo "Hello ". $User["username"]."! How are you?";
// LOGGED IN STUFF HERE FAG
}else{
echo "Wrong password.";
}
}else{
echo "This username does not exist.";
}
}
?>
[/php]
[QUOTE=commander204;32113876]You can even optimize the query!
[php]
<?php
if(isset($_POST)){
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$password = $password; // encrypt that shit here, bitch. (md5, sha, etc)
$checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."' LIMIT 1");
if(mysql_num_rows($checklogin) == 1){
$result = mysql_fetch_array($checklogin);
if($result["password"] == $password){
$User = $result;
echo "Hello ". $User["username"]."! How are you?";
// LOGGED IN STUFF HERE FAG
}else{
echo "Wrong password.";
}
}else{
echo "This username does not exist.";
}
}
?>
[/php][/QUOTE]
You could optimize it a little bit more by just fetching the fields you need (in this case password and perhaps id).
[QUOTE=thf;32113954]You could optimize it a little bit more by just fetching the fields you need (in this case password and perhaps id).[/QUOTE]
Yes, but if he is a beginner I wouldn't worry about that so much. Could get a headache later in case you forget to fetch a value or something.
I figured doing the two would make it a little more understandable...
Sorry, you need to Log In to post a reply to this thread.