Scrowler
12-15-2003, 05:21 AM
alright, ive written a login system where it checks ur input (duh) and then gets a number, 0 or 1 from an Administrator column in the db, and if its 1 it takes you to admin.php and if its 0 it takes you to user.php
now the admin one if working fine, but when i login to the user.php one, i can see my content. i think its something to do with my if statements, ill post the code for both login.php and user.php
( index.php?id=7 is a login form )
include 'config.php';
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = mysql_query("SELECT * FROM users") or die(mysql_error());
while($row=mysql_fetch_array($query)){
if(($username==$row['Username'])&&($password==$row['Password'])){
if($row['Administrator'] == 1){
$_SESSION['isrobbieloggedin'] = 1;
$_SESSION['adminname'] = $row['Name'];
header("Location: admin.php"); } else {
$_SESSION['username'] = $row['Name'];
$_SESSION['isuserloggedin'] = 1;
$_SESSION['userid'] = $row['id'];
header("Location: user.php");
}
}
}
if(!$username == NULL){ echo $username.', y'; } else { echo 'Y'; }
echo 'our username or password was incorrect. Please hit the back button and try again.';
( login.php )
$id = $_SESSION['userid'];
$query = mysql_query("SELECT * FROM users WHERE id = '$id'") or die(mysql_error());
while($row = mysql_fetch_array($query)){
if(isset($_POST['Submit'])){
$id = $_SESSION['userid'];
$name = $_SESSION['username'];
$website = $_POST['website'];
$testemonial = $_POST['testemonial'];
mysql_query("INSERT INTO testemonials(Testemonial, Author, Website, UserID) VALUES('$testemonial','$name','$website','$id')") or die(mysql_error());
mysql_query("UPDATE users SET HasPosted = '1' WHERE id = '$id'") or die(mysql_error());
echo 'Your testimonial has been added. You <b>cannot</b> edit or post another or delete your testimonial.';
} else {
if($row['HasPosted']==0){ ?>
<div align="center">
<form action="user.php" method="post" name="post" id="post">
<p> </p>
<table width="500" border="0">
<tr>
<td width="95" align="center" valign="middle"><div align="center">Your
testemonial:</div></td>
<td width="395"> <div align="center">
<textarea name="testemonial" cols="60" rows="10" id="textarea"></textarea>
</div></td>
</tr>
<tr>
<td align="center" valign="middle"><div align="center">Posted by:</div></td>
<td><div align="center"><? echo $_SESSION['username']; ?> </div></td>
</tr>
<tr>
<td align="center" valign="middle"><div align="center">Your URL:</div></td>
<td> <div align="center">
<input type="text" name="website">
</div></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"> <div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
<p> </p>
</form>
</div>
</td>
<?
} else {
echo 'You have already posted your testimonial.';
}
}
}
( user.php )
i think it's where my if statement says if($condition== ... im not sure why but i get different results when i change the two == to one =.. which should i use and how to get this script working?
btw, instead of seeing what i should on user.php i just see blank.
now the admin one if working fine, but when i login to the user.php one, i can see my content. i think its something to do with my if statements, ill post the code for both login.php and user.php
( index.php?id=7 is a login form )
include 'config.php';
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = mysql_query("SELECT * FROM users") or die(mysql_error());
while($row=mysql_fetch_array($query)){
if(($username==$row['Username'])&&($password==$row['Password'])){
if($row['Administrator'] == 1){
$_SESSION['isrobbieloggedin'] = 1;
$_SESSION['adminname'] = $row['Name'];
header("Location: admin.php"); } else {
$_SESSION['username'] = $row['Name'];
$_SESSION['isuserloggedin'] = 1;
$_SESSION['userid'] = $row['id'];
header("Location: user.php");
}
}
}
if(!$username == NULL){ echo $username.', y'; } else { echo 'Y'; }
echo 'our username or password was incorrect. Please hit the back button and try again.';
( login.php )
$id = $_SESSION['userid'];
$query = mysql_query("SELECT * FROM users WHERE id = '$id'") or die(mysql_error());
while($row = mysql_fetch_array($query)){
if(isset($_POST['Submit'])){
$id = $_SESSION['userid'];
$name = $_SESSION['username'];
$website = $_POST['website'];
$testemonial = $_POST['testemonial'];
mysql_query("INSERT INTO testemonials(Testemonial, Author, Website, UserID) VALUES('$testemonial','$name','$website','$id')") or die(mysql_error());
mysql_query("UPDATE users SET HasPosted = '1' WHERE id = '$id'") or die(mysql_error());
echo 'Your testimonial has been added. You <b>cannot</b> edit or post another or delete your testimonial.';
} else {
if($row['HasPosted']==0){ ?>
<div align="center">
<form action="user.php" method="post" name="post" id="post">
<p> </p>
<table width="500" border="0">
<tr>
<td width="95" align="center" valign="middle"><div align="center">Your
testemonial:</div></td>
<td width="395"> <div align="center">
<textarea name="testemonial" cols="60" rows="10" id="textarea"></textarea>
</div></td>
</tr>
<tr>
<td align="center" valign="middle"><div align="center">Posted by:</div></td>
<td><div align="center"><? echo $_SESSION['username']; ?> </div></td>
</tr>
<tr>
<td align="center" valign="middle"><div align="center">Your URL:</div></td>
<td> <div align="center">
<input type="text" name="website">
</div></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"> <div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
<p> </p>
</form>
</div>
</td>
<?
} else {
echo 'You have already posted your testimonial.';
}
}
}
( user.php )
i think it's where my if statement says if($condition== ... im not sure why but i get different results when i change the two == to one =.. which should i use and how to get this script working?
btw, instead of seeing what i should on user.php i just see blank.