Cant run sql on server using mysql_query()

ezryder

Member
Apr 30, 2004
7
0
151
Hi,
I cannot seem to run any sql on my host via php. I have the following script:

Code:
<?php
   include("../Scripts/mysqlLogin.inc"); 
   echo "<link rel='stylesheet' href='../emx_nav_left.css' type='text/css'>";
  /***************CONNECTION FOR SERVER*****************************************/
  $dbh=mysql_connect ($host, $user, $password) 
  	or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db ($database);    
  /*****************************************************************************/

      $sql = "SELECT * FROM teachers                     
              WHERE TeacherUser='$TeacherUser'";
      $result = mysql_query($sql)
                  or die("Couldn't execute query2. $sql");
?>
It returns this:

Code:
Couldn't execute query2. SELECT * FROM teachers WHERE TeacherUser=''
This tells me I have connected to the database but my query could not be executed. I know that if I run the sql
Code:
SELECT * FROM teachers WHERE TeacherUser=''
which doesn't work via this script into my database via cpanel it is fine. I've also tried with and without the ";" at the end of my sql.

What else could be the problem? Not being able to run any sql on my server is stopping everything!!! Please help me!! :angry:
 

titus crow

Registered
Mar 24, 2003
2
0
151
You need to add a user to the database

You probably made a database but not a user to access it or you made a user but didnt give the user acces to the database

I've seen lots of people make that mistake

Just go check and see if you have any users that are added to the db user list

It will give you the above error because the database exists but it can not excute commands because it doesnt have access to