Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 12th, 2003, 10:53 PM
Andrus Andrus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 8 Andrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
newbie needs a once over

hey guys could any of you give this a once over, and tell me if it might remotely work
also i got some Q's at the end


the login:
Code:

<?
include"(header.php)";
include"(dbconnect.php)";
?>
<form method=post action="<?echo $PHP_SELF?>">
<table cellpadding=2 cellspacing=0 border=0>
<td>Username:</td><td><input type="text" name="username" size=10></td><tr>
<td>Password:</td><td><input type="password" name="password" size=10></td><tr>
<td>&nbsp;</td><td><input type="submit" name="submit" value="Log In"></td>
</table></form>


<?
if ($submit) {
$result=mysql_query("select * from users where name='$username'",$db) or die ("error");
while ($row=mysql_fetch_array($result)) {
if ($row["password"]==$password) {
printf("Successfully Logged In!<a href=\"main.php?\"'>Click Here</a>");
}
}
}

include"(footer.php)";
?>


dbconnect.php:
Code:
$db=mysql_connect("localhost","user","pass") or die ("error"); 
mysql_select_db("database",$db) or die ("error");


annnnnnddddddd to stay logged in i need something like a cookie,
where would i put the cookie? and how to i edit to cookie to include what page they were on so if the press back and click a link it wont work?

Reply With Quote
  #2  
Old July 13th, 2003, 11:55 AM
wannabe wannabe is offline
=) wannabe?
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2002
Location: florida
Posts: 2,153 wannabe User rank is Lance Corporal (50 - 100 Reputation Level)wannabe User rank is Lance Corporal (50 - 100 Reputation Level)wannabe User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 21 h 58 m 25 sec
Reputation Power: 9
Send a message via AIM to wannabe Send a message via Yahoo to wannabe
just try it and find out.

i think u got include syntax wrong. it should be include("header.php");

if each user is unique u dont need the while loop. if they're not unique then u select them wrong. cause you need to able to identify each user as a unique user.

so u could've just done
PHP Code:
 $result =mysql_query("SELECT password FROM users WHERE user = '$username'");

if (
mysql_result($getpass,0) == $password)
{
  
// set cookie


also if you're using a newer version of php. chances are register_globals is OFF. so the variables you get from the form with method post. should be $_POST['submit'] and not just $submit. same goes for $password should be $_POST['password']

u also got a single quote in <a href=\"main.php\"> dont know why u have it there.

you'd need to modify it a bit to work with cookies and over multiple pages.

=) but really, if u're a noob like me just try things. u'll get them right, eventually. php isnt the hardest one. after u learn the syntax u'll worry about logic.

Reply With Quote
  #3  
Old August 21st, 2003, 08:13 PM
Andrus Andrus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 8 Andrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks,

a little bit revised:

Quote:
if ($do=="login") {

$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);

$q="SELECT * from users WHERE name='$name' AND password='$password'";

$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());

$numrows = mysql_num_rows($result);

if($numrows==0) {
echo "Login incorrect! Please go back and retry";
}

else {
$name=$name;
session_register("name");

$q="SELECT * from logs";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());

$numrows = mysql_num_rows($result);

$time = date("H:i:s, d-m-Y");
$ip = getenv("REMOTE_ADDR");
$id = $numrows + 1;

$q="INSERT into logs (id,name,time,ip)
VALUES ('$id','$name','$time','$ip')";

$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());

header("Location: main.php");
}

}

?>

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > newbie needs a once over


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT