Jump to content

[SOLVED] basic $result = mysql_query problem


unistake

Recommended Posts

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 :)

Link to comment
Share on other sites

....

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

 

 

 

Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.