Please help im new to php

Hello Im kinda new to php so i still get lost easly. Im having trouble finding the error in this script the part of the script for members works fine the error is some where in the admin code is there a easer way to do this? all i need it to do is check the database if admin=0 not an admin if admin =1 admin. the hole mod thing came in with me trying to go the same roughtt as the members script cuz it works butt ill just use the members script till i get help

$conn = mysql_connect("localhost","","");
$db = mysql_select_db("www_arcgaming_com");

$username = $_POST["username"];
$password = $_POST["password"];

$result = MYSQL_QUERY("SELECT * from users WHERE username='$username'and password='$password'")
or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

$username = $worked[username];
$password = $worked[password];
$email = $worked[email];
$fname = $worked[fname];
$lname = $worked[lname];

$admin = $_POST["admin"];
$mod = $_POST["mod"];

$admin = MYSQL_QUERY("SELECT * from users WHERE anmin='$admin' and mod='$mod'")
or die (Not an admin);

$modder = mysql_fetch_array($admin);

$admin = $modder[admin];
$mod = $modder[mod];
echo "Welcome $fname $lname";
echo "Mod Script Working";


  • [b][red]This message was edited by Moderator at 2005-3-23 1:21:15[/red][/b][hr]
    First of all you shoud use " ' " when you het keys from an array like this:
    $username = $worked['username'];
    $password = $worked['password'];
    $email = $worked['email'];
    $fname = $worked['fname'];
    $lname = $worked['lname'];

    Than if you want to use variables in a mysql query I would do it this way and not use the " ' " width the variables:
    $query = "SELECT * from users WHERE username=$username and password=$password";
    $results = mysql_query($query) or die ("YOU ERROR");
    $worked = mysql_fetch_array($results);

    The thing with " ' " is that you give PHP the command to exactly use the text between the " ' " operators. So you're query is executed with the variables values $username and $password. Leave them out of there and PHP will use the variable values that refer to the variables.

    Just to check your query. Try to echo your query before you execute it. Look for the variables you inserted in the query.

    Hope this helps you a bit.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion