Log in

View Full Version : PHP Code MYSQL Code



KyleSmith
08-02-2010, 12:26 PM
I have some PHP code where i need it so it will redirect them to the homepage if the accounttype is standard.

I have the code but it dont seem to be redirecting them.




<?php session_start();
include 'config.php';
$username = addslashes($_POST['username']);

$sql = "SELECT adminlevel,accounttype FROM users WHERE username = '" . $username . "' AND accounttype = 'standard'";
echo MySQL_Error();
$result = mysql_query($sql);
$row = mysql_fetch_row($result);

if(!isset($_SESSION['logged_in']) || !isset($_SESSION['username'])) {
header("location: index.php");
exit;
}
if($row['accounttype'] == 'standard') {
header("location: index.php");
exit;
}

?>
<style type="text/css">
<!--
body {
background-image: url(http://lv-cnr.com/bg.png);
}
-->
</style>

Tomm
08-02-2010, 02:49 PM
mysql_fetch_row returns a numerical array and you're trying to use it as an associative array. Either use $row[1] == 'standard' or change mysql_fetch_row to mysql_fetch_assoc

KyleSmith
08-02-2010, 03:40 PM
So like

$row = mysql_fetch_assoc($result);

KyleSmith
08-02-2010, 03:42 PM
For some reason it still lets me on the page even though my account is standard

Want to hide these adverts? Register an account for free!