[SOLVED] looking for code
Moderator: General Moderators
looking for code
anyone have a simple mySQL/php script that for multiple users?
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
something like this would work
now to say "hello yourname";
use
good luck
(please note this is using plain text password system, some adjustments wil need to be made to incorporate MD5 hashing)
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";
}use
Code: Select all
session_start();
print "$_SESSION[username]";(please note this is using plain text password system, some adjustments wil need to be made to incorporate MD5 hashing)
umm theres a problem, but i dont know why..
Error:
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">» Menu</span><br>");
echo ("--» Modify News<br>");
echo ("---» Add News<br>");
echo ("---» Edit/Delete News <br>");
echo ("--» Modify Users<br>");
echo ("---» Add User<br>");
echo ("---» Edit/Delete Users <br>");
echo ("--» Site Stats<br>");
echo ("--» Connect to:<br>");
echo ("---» Live Support <br>");
echo ("---» PerlDesk<br>");
echo ("---» PLesk <br>");
echo ("--» Admin Notes<br>");
echo ("---» Read Notes<br>");
echo ("---» Add Note<br>");
echo ("--» Modify Services <br>");
echo ("---» Add Service<br>");
echo ("---» Edit Service<br>");
echo ("---» 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"; }
?>Line 199:Parse error: parse error, unexpected '{' in c:\program files\apache group\apache\htdocs\project3\admin.php on line 199
Code: Select all
if (isset($uname, $pass) {- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
ok new problem....
PHP Code:
Login Form:
Problem:
Wont display anything (the menu) after loged in.. just shows the login form, how fix?
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">» Menu</span><br>");
echo ("--» Modify News<br>");
echo ("---» Add News<br>");
echo ("---» Edit/Delete News <br>");
echo ("--» Modify Users<br>");
echo ("---» Add User<br>");
echo ("---» Edit/Delete Users <br>");
echo ("--» Site Stats<br>");
echo ("--» Connect to:<br>");
echo ("---» Live Support <br>");
echo ("---» PerlDesk<br>");
echo ("---» PLesk <br>");
echo ("--» Admin Notes<br>");
echo ("---» Read Notes<br>");
echo ("---» Add Note<br>");
echo ("--» Modify Services <br>");
echo ("---» Add Service<br>");
echo ("---» Edit Service<br>");
echo ("---» 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
<br><form name="form" method="post" action="admin.php?loggain=1">
<br>
<span class="emph">Admin Login</span><br>
<center>
Username:<br>
<input name="username" type="text" id="username">
<br>
Password:<br> <input name="pass" type="password" id="pass">
<br>
<input name="submit" type="submit" value="Login"></center>
</form>Problem:
Wont display anything (the menu) after loged in.. just shows the login form, how fix?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$uname = $_POST['username'];
$pass = $_POST['pass'];
// now chck they are both set
if ((isset($user)) && (isset($pass))) {- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
might be coming from this:
Code: Select all
echo mysql_error();
$result = mysql_query($result) or die (mysql_error());
echo mysql_error();