Jump to content

Cannot do a query?


DarrenReeder

Recommended Posts

HEllo,

 

I have connected to my database with "#include ("Connections.php");" at top of my code, and it connects perfectly with no error, Although when i try to run a query i get errors...THis is my connection.php and the query in the index.html Respectively....

 

<?php
session_start();

$host="localhost";
$username="root";
$password="";
$db_name="up";


//connect to database
mysql_connect("$host","$username","$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select Database");

//login check function
function loggedin()
{
if (isset($_SESSION['username']))
{
$loggedin = true;
return $loggedin;

}
}

function IsAdmin()
{
$realname =$_SESSION['username'];
$query="select * FROM accounts WHERE username ='$realname'";
$result=mysql_query($query);
$num=mysql_num_rows($result);

$rows=mysql_fetch_array($result);
$admin=$rows['Admin'];
if ($admin >= 1)
{
$IsAdmin = true;
return $IsAdmin;

}
}


?>

 

	$query=mysql_query("SELECT * FROM accounts WHERE username='darren'");
$row=mysql_num_rows($query);
}
if($row==0)
{
echo"Yes";
}
if($row==1)
{
echo"Name already taken!!";
}

 

And this is the errors..

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\UniversalProgramming\Register.php on line 67

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\UniversalProgramming\Register.php on line 67

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\UniversalProgramming\Register.php on line 68

 

Now this is very strange because as you can see i use those if statements...and they work perfectly but i still get Errors on the queries.. So help me please :D

Link to comment
https://forums.phpfreaks.com/topic/185439-cannot-do-a-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.