unistake Posted September 10, 2009 Share Posted September 10, 2009 Hi all, I have a bit of a problem with this members page script The $result seems to have a problem that says "Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\ on line 13" <?php session_start(); if (@$_SESSION['auth'] !="yes") { echo "you are not logged in!"; include("login.html"); } else { $logName = $_SESSION['logname']; echo "you are logged in $logName!"; $today = date("Y-m-d h:i:s"); $sql = "INSERT INTO onlineusers VALUES ('$logName','$today')"; $result = mysql_query($sql) or die("Couldnt execute query."); } ?> Any clues? Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/ Share on other sites More sharing options...
mikesta707 Posted September 10, 2009 Share Posted September 10, 2009 either your user ODBC doesn't have the correct permissions or you set his login name and password wrong. should the password be "NO"? Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916319 Share on other sites More sharing options...
PFMaBiSmAd Posted September 10, 2009 Share Posted September 10, 2009 Your code has nothing in it to make a connection to the mysql server, so when you execute a mysql_query() statement it attempts to make a connection using default values. Where is your code that is supposed to be making the connection to the mysql server? Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916323 Share on other sites More sharing options...
unistake Posted September 10, 2009 Author Share Posted September 10, 2009 Does a connection not stay open when session_start is used? Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916329 Share on other sites More sharing options...
mikesta707 Posted September 10, 2009 Share Posted September 10, 2009 .... session_start() is ussed for sessions, not mysql connections. I suggest you read a simple tutorial on php and mysql if you don't know how to connect to a mysql database, but it should look something like $conn = mysql_connect("localhost", "username", "password") or die(mysql_error());//connect to mysql $select = mysql_select_db("test") or die(mysql_error());//select the database "test" //now we can do some queries Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916333 Share on other sites More sharing options...
unistake Posted September 10, 2009 Author Share Posted September 10, 2009 I can connect to a database, but didnt think that was needed in this case! Ill give it a go! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916336 Share on other sites More sharing options...
unistake Posted September 10, 2009 Author Share Posted September 10, 2009 yep it worked thanks! Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916337 Share on other sites More sharing options...
unistake Posted September 10, 2009 Author Share Posted September 10, 2009 Also I have a problem with this logout code, same sort of problem, something to do with $result... <?php session_start(); $dbhost = "host"; $dbuser = "user"; $dbpassword = "password"; $db = "db"; $cxn = mysqli_connect($dbhost, $dbuser, $dbpassword, $db) or die ("cant connect to database!"); $logName = $_SESSION['logname']; echo "you have logged out $logName!"; $today = date("Y-m-d h:i:s"); $sql = "DELETE FROM onlineusers WHERE loginName=$logName"; $result = mysqli_query($cxn, $sql) or die("Couldnt execute query."); session_destroy(); header("Location: login.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916353 Share on other sites More sharing options...
mikesta707 Posted September 10, 2009 Share Posted September 10, 2009 im gonna assume that loginName is a varchar data type try $sql = "DELETE FROM onlineusers WHERE loginName='$logName'" you usually want to surround varchars with single quotes. also that header isn't going to work unless you get rid of the echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916355 Share on other sites More sharing options...
unistake Posted September 10, 2009 Author Share Posted September 10, 2009 Mike you are a legend! that got it working. Howcome having an echo will not allow the header to work though? Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916357 Share on other sites More sharing options...
mikesta707 Posted September 10, 2009 Share Posted September 10, 2009 headers won't work if you output something to the page. Well actually there IS a work around, but most of the time if you are forced to use the work around, you should rethink how you are coding the page. Its just something about headers. check out the PHP manual if you want more information though. Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916359 Share on other sites More sharing options...
unistake Posted September 10, 2009 Author Share Posted September 10, 2009 ok thanks for the heads up Quote Link to comment https://forums.phpfreaks.com/topic/173838-solved-basic-result-mysql_query-problem/#findComment-916361 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.