Jump to content

thewooleymammoth

Members
  • Posts

    768
  • Joined

  • Last visited

    Never

Everything posted by thewooleymammoth

  1. thanks for the help with the last problem btw now i have a new problem. I tried not to look at the sample code too much cause i wanted to figure out my own way of doing it. afterall it is practice. here is my code... <?php $username="root"; $password="php"; $database="userlist"; $table="login"; $connectmysql="mysql_connect(localhost,$username,$password)"; $selectdb="mysql_select_db('$database') or die('Could not select database')"; $query1="SELECT*FROM $table"; $query2="SELECT*FROM $table WHERE username='$user'"; $query3="SELECT*FROM $table WHERE username='$userpass'"; $result1="mysql_query($query1)"; $result2="mysql_query($query2)"; $result3="mysql_query($query3)"; $user2=$_COOKIE['auth']; if($_COOKIE['auth']) { echo "Welcome $user2 Enjoy the site"; } elseif (!isset($_POST['loggedin'])) { echo "<a>please login:</a><br> <form method='post' action='index.php'> Username:<input type='text' name='username'><br> Password:<input type='text' name='password'><br> <input type='submit' name='loggedin' value='Log In'><br> <a href='resister.php'>Register here</a>"; } elseif (isset($_POST['loggedin'])) { $user=$_POST['username']; $userpass = $_POST['password']; $connectmysql; $selectdb; if($user==$result2) { if($userpass == $result3) { echo "Thank you for logging in"; setcookie ("auth","$user"); } elseif ($user!=$result2) { echo "Sorry Wrong username/Password combonation"; } } } else { echo "error"; } ?> i get to the login form alright but when i press login the page goes blank and there is no source... idk why it would do that or what i should do to continue debugging... sorry to bother you guys so much. been trying to figure it out for a half an hour and i got no solution so far at all idk where to even start looking
  2. seriously im retarded... the problem was $user="$_POST['username']"; needed to be $user=$_POST['username']; damn it
  3. yea sorry i couldnt remember wwaht the tag was for code ??? which makes me an idiot... but i figured it out eventually. and for the bottom part of the code its checking to see if the cookie placed on there computer (which contains thier password) matches the password stored in mysql. i redid the code and placed it at the top of the page because i realized the site would never execute that code because it would make you relogin everypage. so that code was moved to the top and the other code was placed below it. it might not make sence because im new and maybe its just a messed up crappy idea... idk... anyways thanks for the help. echo "Thank you for logging in"; setcookie ["$user ","$userpass "]; elseif($_COOKIE['$user'] == $userpass) { echo "Welcome $user Enjoy the site"; }*/ ?> wouldnt that translate into $userpass == $userpass ?
  4. yea thats probably what happened, but i still have the problem, i realized that my code wouldnt work as mentioned above, just because things were out of order. my new code is <?php $username="php"; $password="ironpass"; $database="userlist"; $table="login"; $connectmysql="mysql_connect(localhost,$username,$password)"; $selectdb="mysql_select_database($database) or die('unable to select database')"; if(isset($_COOKIE['user'])) { if ($_COOKIE['user'] == $userpass) { echo "Welcome $user Enjoy the site"; } } elseif (!isset($_POST['loggedin'])) { echo "<a>please log in</a><br><form method='post'><br>Username:<input type='text' name='username'><br>Password:<input type='text' name='password'><br><input type='submit' name='loggedin' value='Log In'><a href='resister.php'>Register here</a>"; } elseif (isset($_POST['loggedin'])) { $user="$_POST['username']"; $userpass = "$_POST['password']"; $query1="SELECT*FROM login"; $query2="SELECT*FROM login WHERE username='$user'"; $query3="SELECT*FROM login WHERE username='$userpass'"; $result1="mysql_query($query1)"; $result2="mysql_query($query2)"; $result3="mysql_query($query3)"; $connectmysql @mysql_select_database($database) or die('unable to select database'); if($user==$result2) { if($userpass == $result3) { echo "Thank you for logging in"; setcookie ["$user ","$userpass "]; } } } ?> but i still have the original problem ive heard that easy php could be the problem... so if someone could run it on thier machine and tell me if it works that would be nice... unless someone can point out my error, i would prefer that, thanks again! also if someone could help me out with the connecting to the database please, im just looking at the line @mysql_select_database($database) or die('unable to select database'); and it looks just wrong. i would appreciate if someone could set me straight on that, thanks
  5. ok, ill try could you explain to me what you changed though? EDIT: i tried it, i belive where you put }elseif{ (isset($_POST['loggedin'])) you ment }elseif (isset($_POST['loggedin'])) { ? anyways i still get the same error with the new programming. Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\easyphp1-8\www\website temp\index2.php on line 18 only its on line 18 because you format your code differently then i do line 18 is still $user="$_POST['username']";
  6. I just started using php and i figured what better to practice on then creating a ficticious login script. Im using easyphp and here is the code. <?php $username="php"; $password="ironpass"; $database="userlist"; $table="login"; $connectmysql="mysql_connect(localhost,$username,$password)"; if (!isset($_POST['loggedin'])) { echo "<a>please log in</a><br><form method='post'><br>Username:<input type='text' name='username'><br>Password:<input type='text' name='password'><br><input type='submit' name='loggedin' value='Log In'><a href='resister.php'>Register here</a>"; } elseif (isset($_POST['loggedin'])) { $user="$_POST['username']"; $userpass = "$_POST['password']"; $query1="SELECT*FROM login"; $query2="SELECT*FROM login WHERE username='$user'"; $query3="SELECT*FROM login WHERE username='$userpass'"; $result1="mysql_query($query1)"; $result2="mysql_query($query2)"; $result3="mysql_query($query3)"; $connectmysql mysql_select_db($database) or die("unable to select database"); if($user == $result2) { if($userpass == $result3) { echo "Thank you for logging in"; setcookie ["$user ","$userpass "]; } } } elseif($_COOKIE['user'] == $userpass) { echo "Welcome $user Enjoy the site"; } ?> on line 15 which is $user="$_POST['username']"; I get this error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\easyphp1-8\www\website temp\index.php on line 15 its probably some stupid thing i did or the way i wrote it... idk if i can put variables there, but i get the same error when its at the top with the other variables... so im stumped, also if line 15 is removed it gets the same error with the next two variables below it, idk beyond those two cause i stopped checking em. any help is appreciated thanks in advance. btw please dont comment and tell me that thats an insecure way of making a login script becasue i dont care, im just practicing.
  7. i was following this tutorial the original sources are at http://www.neoblob.com/phpsquad/index.php?page=sources under login and phpmysql registration, and i cant figure out whats wrong with my do_login.php script. <?php $connection = mysql_connect("localhost", "php", "007") or die("error1"); $db = mysql_select_db("user", $connection) or die("error2"); $sql = "SELECT id FROM users WHERE username='$_POST[username]' AND password='$_POST[password]'" or die("error3"); $result = mysql_query($sql) or die("error4"); $num = mysql_num_rows($result) or die("error5"); if ($num > 0) { //USER AND PASS ARE CORRECT $id = mysql_fetch_assoc($result) or die("error6"); setcookie("auth", "yes", time()+3600); setcookie("id", $id['id']); setcookie("username", $id['username']); header ("Location: main.php") or die("error7"); }else { header ("Location: incorrect.php") or die("error8"); }; ?> its returning back "error 5" which i added while trying to figure out what the problem was. which mean something is wrong with the code "$num = mysql_num_rows($result) or die("error5");" or one of the variables attached right? i cant figure out what, help appreciated, i also have another question, how do you restrict certain pages based on this info??? thanks again.
×
×
  • 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.