[SOLVED] looking for code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

looking for code

Post by bla5e »

anyone have a simple mySQL/php script that for multiple users?
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

For multiple users to do what? Login to a site? Send each other money? Dance around a maypoll butt naked? etc etc
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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)
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

thanks
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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) {
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

isset($uname) && isset($pass)
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

still same error :(
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

if ((isset($user)) && (isset($pass)))
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

u so smart :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

i know
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Query was empty
wtf?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

might be coming from this:

Code: Select all

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