amp2000 Posted April 2, 2003 Share Posted April 2, 2003 Hi I\'m having a few problems with getting a part of a script working. Here is the relevant code <?php include("config.php"); include("header.php"); $dbh = mysql_connect ($dbhost, $dbuname, $dbpass) or die ( \'I cannot connect to the database because: \' . mysql_error()); mysql_select_db ($dbname) or die (mysql_error()); // Perform query on travel table $query = "SELECT * FROM travel"; $result = mysql_query($query) or die("Error:" .mysql_error()); //Authentication, user will not see results unless logged on global $user, $sitename; cookiedecode($user); $username = $cookie[1]; if ($username == "") { # $username = "Anonymous"; echo "You need to Logon"; exit; } else { echo "OK, Your logged on, now checking to see are you a directorate"; //Perform query on names of directorates $query2 = "SELECT name FROM managers"; $result2 = mysql_query($query2) or die("Error:" .mysql_error()); while ($row2 = mysql_fetch_row($result2)) { if (!$username == $row2[0]) { echo "Your logged on but your not a directorate, bye!"; exit; } else { echo "<br>"; echo \'Your a Directorate!\'; }}} echo OpenTable(); // Retrieve values while ($row = mysql_fetch_row($result)) { ###### Rest of Script goes here ####### Now my problem is with this part (I think) $query2 = "SELECT name FROM managers"; $result2 = mysql_query($query2) or die("Error:" .mysql_error()); while ($row2 = mysql_fetch_row($result2)) { if (!$username == $row2[0]) { echo "Your logged on but your not a directorate, bye!"; exit; If I am not logged on to my PHPnuke site I get the error \"You need to Logon\" & it exits as expected, this part works fine. I want it so that if a user is logged on, it checks to see is their name in the managers table & if it\'s not they get the error \"Your logged on but your not a directorate, bye!\". The problem is any user who is logged on to the site is told Your a Directorate! when they are not in my managers table Can one of you experts take a look at my code & tell me if I\'m doing something obviously wrong :wink: Also, notice the way I have added a 2 after the variable names for the 2nd query, do I need to do that :?: Thanks in advance for any replies Quote Link to comment Share on other sites More sharing options...
shivabharat Posted April 2, 2003 Share Posted April 2, 2003 //Perform query on names of directorates $query2 = "SELECT name FROM managers"; $result2 = mysql_query($query2) or die("Error:" .mysql_error()); while ($myrow = mysql_fetch_row($result)) { [quote]Now in the myrow supply the correct row value in which u havethe name field [/quote] $name = myrow[1]; $a = strcmp(\'$username\',\'$name\'); if ($a == \'0\') { echo "<br>"; echo \'Your a Directorate!\'; } else { echo "Your logged on but your not a directorate, bye!"; exit; } } Hope this helps!! Quote Link to comment Share on other sites More sharing options...
amp2000 Posted April 4, 2003 Author Share Posted April 4, 2003 Thanks for the reply :wink: Your code didnt work though, well it did work but when I change the name of the directorate in my managers table the script fails to see the changes I made. Here is the code I finally got to work for me global $user, $sitename; cookiedecode($user); $username = $cookie[1]; $query2 = "SELECT name FROM managers WHERE name = \'$username\'"; $result2 = mysql_query($query2) or die("Error:" .mysql_error()); $result2_rows = mysql_num_rows ($result2); if ($result2_rows == 0) { echo "Your logged on but your not a directorate, bye!"; exit; } Cheers amp2000 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.