The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cant run sql on server using mysql_query()

Discussion in 'Database Discussions' started by ezryder, May 3, 2004.

  1. ezryder

    ezryder Member

    Joined:
    Apr 30, 2004
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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:
     
  2. titus crow

    titus crow Registered

    Joined:
    Mar 24, 2003
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  3. ezryder

    ezryder Member

    Joined:
    Apr 30, 2004
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Thanks! I hadn't set up any users on the database.
     
  4. titus crow

    titus crow Registered

    Joined:
    Mar 24, 2003
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    no problem
     
Loading...

Share This Page