Page 1 of 2

looking for code

Posted: Sun Jun 13, 2004 1:41 am
by bla5e
anyone have a simple mySQL/php script that for multiple users?

Posted: Sun Jun 13, 2004 3:49 am
by launchcode
For multiple users to do what? Login to a site? Send each other money? Dance around a maypoll butt naked? etc etc

Posted: Sun Jun 13, 2004 10:00 am
by bla5e
just a code that:

- has a login page
- when loged in, says "welcome $user-that-loged-in"
- if not wrong p/w takes them back the login back

Posted: Sun Jun 13, 2004 10:23 am
by malcolmboston
something like this would work

Code: Select all

// simplify the variables
$uname = $_POST['username'];
$pass = $_POST['password'];
// now chck they are both set
if (isset($uname, $pass)
{
// run a mysql query something like below
$query = "SELECT * FROM table WHERE username = '$uname' AND password = '$pass'";
$result = mysql_query($result) or die (mysql_error());
// now run a conditional mysql num rows to see affected records
$num_rows = mysql_num_rows($result);
if ($num_rows == 1)
{
// this guy is a user
$_SESSION['username'] = $uname;
header("Location: somewhere_logged_in.php");
}
else
{
// unknown user
header("redirectback.php");
}
}
else
{
print "Not all details have been filled out";
}
now to say "hello yourname";

use

Code: Select all

session_start();
print "$_SESSION[username]";
good luck

(please note this is using plain text password system, some adjustments wil need to be made to incorporate MD5 hashing)

Posted: Sun Jun 13, 2004 2:39 pm
by bla5e
thanks

Posted: Sun Jun 13, 2004 2:59 pm
by bla5e
umm theres a problem, but i dont know why..

Code: Select all

<?php				
				
				
					$uname = $_POST['username']; 
					$pass = $_POST['password']; 
						// now chck they are both set 
						if (isset($uname, $pass) { 
							// run a mysql query something like below 
							//mysql start
							error_reporting(E_ALL);  
							$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
							mysql_select_db ("krilen", $dbh);
							$query = "SELECT * FROM krilen WHERE username = '$uname' AND password = '$pass'"; 
							echo mysql_error();
							$result = mysql_query($result) or die (mysql_error()); 
							echo mysql_error();
								// now run a conditional mysql num rows to see affected records 
								$num_rows = mysql_num_rows($result); 
								if ($num_rows == 1) { 
									// this guy is a user 
										$_SESSION['username'] = $uname; 
										echo ("<span class="emph">Welcome, ");										
										print "$_SESSION[username]";  
										echo ("</span><br>");
										echo ("<br class="short">");
										echo ("<br class="short">");
										echo ("<span class="emph">&raquo; Menu</span><br>");
										echo ("--&raquo; Modify News<br>");
										echo ("---&raquo; Add News<br>");
										echo ("---&raquo; Edit/Delete News <br>");
										echo ("--&raquo; Modify Users<br>");
										echo ("---&raquo; Add User<br>");
										echo ("---&raquo; Edit/Delete Users <br>");
										echo ("--&raquo; Site Stats<br>");
										echo ("--&raquo; Connect to:<br>");
										echo ("---&raquo; Live Support <br>");
										echo ("---&raquo; PerlDesk<br>");
										echo ("---&raquo; PLesk <br>");
										echo ("--&raquo; Admin Notes<br>");
										echo ("---&raquo; Read Notes<br>");
										echo ("---&raquo; Add Note<br>");
										echo ("--&raquo; Modify Services <br>");
										echo ("---&raquo; Add Service<br>");
										echo ("---&raquo; Edit Service<br>");
										echo ("---&raquo; Delete Service</p>");
										//header("Location: somewhere_logged_in.php"); 										
								} 
								else { /* unknown user*/	echo ("<b><font color='red'>Wrong Password / Username!</font></b>"); } 
							} 
							else { print "Not all details have been filled out"; } 
							
				
				 ?>
Error:
Parse error: parse error, unexpected '{' in c:\program files\apache group\apache\htdocs\project3\admin.php on line 199
Line 199:

Code: Select all

if (isset($uname, $pass) {

Posted: Sun Jun 13, 2004 3:02 pm
by feyd
isset($uname) && isset($pass)

Posted: Sun Jun 13, 2004 3:04 pm
by bla5e
still same error :(

Posted: Sun Jun 13, 2004 3:10 pm
by John Cartwright
if ((isset($user)) && (isset($pass)))

Posted: Sun Jun 13, 2004 3:11 pm
by bla5e
u so smart :)

Posted: Sun Jun 13, 2004 3:13 pm
by John Cartwright
i know

Posted: Sun Jun 13, 2004 3:21 pm
by bla5e
ok new problem....

PHP Code:

Code: Select all

<?php	
				
					$uname = $_POST['username']; 
					$pass = $_POST['pass']; 
						// now chck they are both set 
						if ((isset($user)) && (isset($pass)))  {
							// run a mysql query something like below 
							//mysql start 	
							if ($_GET['loggain'] == "1") {						
							$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
							mysql_select_db ("krilen", $dbh);
							$query = "SELECT * FROM krilen WHERE username = '$uname' AND password = '$pass'"; 
							echo mysql_error();
							$result = mysql_query($result) or die (mysql_error()); 
							echo mysql_error();
						
								// now run a conditional mysql num rows to see affected records 
								$num_rows = mysql_num_rows($result); 
								if ($num_rows == 1) { 
									// this guy is a user 
										echo ("<span class="emph">Welcome, ");										
										print "$_SESSION[username]";  
										echo ("</span><br>");
										echo ("<br class="short">");
										echo ("<br class="short">");
										echo ("<span class="emph">&raquo; Menu</span><br>");
										echo ("--&raquo; Modify News<br>");
										echo ("---&raquo; Add News<br>");
										echo ("---&raquo; Edit/Delete News <br>");
										echo ("--&raquo; Modify Users<br>");
										echo ("---&raquo; Add User<br>");
										echo ("---&raquo; Edit/Delete Users <br>");
										echo ("--&raquo; Site Stats<br>");
										echo ("--&raquo; Connect to:<br>");
										echo ("---&raquo; Live Support <br>");
										echo ("---&raquo; PerlDesk<br>");
										echo ("---&raquo; PLesk <br>");
										echo ("--&raquo; Admin Notes<br>");
										echo ("---&raquo; Read Notes<br>");
										echo ("---&raquo; Add Note<br>");
										echo ("--&raquo; Modify Services <br>");
										echo ("---&raquo; Add Service<br>");
										echo ("---&raquo; Edit Service<br>");
										echo ("---&raquo; Delete Service</p>");
										//header("Location: somewhere_logged_in.php"); 										
								} else { /* unknown user*/	
								echo ("<b><font color='red'>Wrong Password / Username!</font></b>"); 
								} 
						}
						}
								
				 
				?>

Login Form:

Code: Select all

&lt;br&gt;&lt;form name="form" method="post" action="admin.php?loggain=1"&gt;
					&lt;br&gt;
					&lt;span class="emph"&gt;Admin Login&lt;/span&gt;&lt;br&gt;
					&lt;center&gt;
					Username:&lt;br&gt;
					&lt;input name="username" type="text" id="username"&gt;
					&lt;br&gt;
					Password:&lt;br&gt;	&lt;input name="pass" type="password" id="pass"&gt;
					&lt;br&gt;
					
					&lt;input name="submit" type="submit" value="Login"&gt;&lt;/center&gt;
					&lt;/form&gt;

Problem:

Wont display anything (the menu) after loged in.. just shows the login form, how fix?

Posted: Sun Jun 13, 2004 3:30 pm
by feyd

Code: Select all

$uname = $_POST['username']; 
               $pass = $_POST['pass']; 
                  // now chck they are both set 
                  if ((isset($user)) && (isset($pass)))  {
your variable names are out of sync..

Posted: Sun Jun 13, 2004 4:04 pm
by bla5e
Query was empty
wtf?

Posted: Sun Jun 13, 2004 4:19 pm
by feyd
might be coming from this:

Code: Select all

echo mysql_error(); 
                     $result = mysql_query($result) or die (mysql_error()); 
                     echo mysql_error();