Results 1 to 5 of 5

Thread: Warning: mysql_connect() [function.mysql-connect]: Access denied

  1. #1
    Join Date
    Oct 2008
    Location
    Pasadena, TX
    Posts
    8

    Unhappy Warning: mysql_connect() [function.mysql-connect]: Access denied

    :confused::confused::confused:

    I have a test site on the server located at www.thetitlestor.com/Test Login Web

    In this test site I'm trying to use this page:

    www.thetitlestor.com/Test Login Web/insert.php to add customer registration info from a form to a database set-up in MySQL under database name "Custreg" and table name "custlogon" with the username "thetitl1_ttsprez" and password "test"

    This is the code for that page:

    <html>

    <head>

    <meta http-equiv="Content-Language" content="en-us">

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" x-undefined>

    </head>

    <body>

    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">

    <tr>

    <td><form name="register" method="post" action="insert_ac.php">

    <table width="100%" border="0" cellspacing="1" cellpadding="3">

    <tr>

    <td colspan="3"><div align="center"><strong>Customer Registration Form</strong></div></td>

    </tr>

    <tr>

    <td width="71">Username</td>

    <td width="6">:</td>

    <td width="301"><input name="username" type="text" id="username"></td>

    </tr>

    <tr>

    <td>Password</td>

    <td>:</td>

    <td><input name="password" type="text" id="password"></td>

    </tr>

    <tr>

    <td>Full Name</td>

    <td>:</td>

    <td><input name="fullname" type="text" id="fullname"></td>

    </tr>

    <tr>

    <td>Contact Number</td>

    <td>:</td>

    <td><input name="contactnumber" type="text" id="contactnumber"></td>

    </tr>

    <tr>

    <td>Email</td>

    <td>:</td>

    <td><input name="email" type="text" id="email"></td>

    </tr>

    <tr>

    <td>Project Type</td>

    <td>:</td>

    <td><textarea name="projecttype" type="text" id="projecttype"></textarea></td>

    </tr>

    <tr>

    <td colspan="3" align="center"><input type="submit" name="Submit" value="Register"></td>

    </tr>

    </table>

    </form>

    </td>

    </tr>

    </table>

    </body>

    </html>


    Line 18 of the preceding code submits the information collected from the insert.php page to the following page:

    www.thetitlestor.com/Test Login Web/insert_ac.php

    Again this page is set-up to connect to a MySQL under database name "Custreg" and table name "custlogon" with the username "thetitl1_ttsprez" and password "test"

    This is the code for the insert_ac.php page:

    <html>

    <head>

    <meta http-equiv="Content-Language" content="en-us">

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" x-undefined>

    </head>

    <body>

    <?php

    mysql_error();

    $host="thetitlestor.com"; // Host name

    $username="thetitl1_ttsprez"; // Mysql username

    $password="test"; // Mysql password

    $db_name="thetitl1_Custreg"; // Database name

    $tbl_name="custlogon"; // Table name

    mysql_error();

    // Connect to server and select database.

    mysql_connect("thetitlestor.com", "thetitl1_ttsprez", "test")or die("cannot connect");

    mysql_select_db("thetitl1_Custreg")or die("cannot select DB");

    mysql_error();

    // Get values from form

    $username=$_POST['username'];

    $password=$_POST['password'];

    $fullname=$_POST['fullname'];

    $contactnumber=$_POST['contactnumber'];

    $email=$_POST['email'];

    $projecttype=$_POST['projecttype'];

    mysql_error();

    // Insert data into mysql

    $sql="INSERT INTO $tbl_name(username, password, fullname, contactnumber, email, projecttype)VALUES('$username', '$password', '$username', 'fullname', 'contactnumber', 'email', 'projecttype')";

    $result=mysql_query($sql);

    mysql_error();

    // if successfully insert data into database, displays message "Successful".

    if($result){

    echo "Successful";

    echo "<BR>";

    echo "<a href='insert.php'>Back to main page</a>";

    }

    else {

    echo "ERROR";

    }

    mysql_error();

    // close connection

    mysql_close();

    ?>

    </body>

    </html>

    When entering info onto the insert page and clicking submit, I get the following error message:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'thetitl1_ttsprez'@'box389.bluehost.com' (using password: YES) in /home/thetitl1/public_html/Test Login Web/insert_ac.php on line 35
    cannot connect

    Lines in the 35 area read as follows:


    // Connect to server and select database.

    mysql_connect("thetitlestor.com", "thetitl1_ttsprez", "test")or die("cannot connect");

    mysql_select_db("thetitl1_Custreg")or die("cannot select DB");



    If my eyes are not deceiving me, this portion of code corresponds with this info as follows:

    MySQL under database name "Custreg" and table name "custlogon" with the username "thetitl1_ttsprez" and password "test"

    These pages are meant to have the customer register their info to the database table. This table will also be used by www.thetitlestor.com/Test Login Web/mainlogin.php and this page refers the info to www.thetitlestor.com/Test Login Web/checklogin.php for processing.

    I've double and triple check everything line by line to see if maybe there is something I'm not seeing, but I just don't see what I'm missing. I'm hoping a fresh set of eyes will show me what I'm missing or doing wrong. You guys always help me out a lot and I'm hoping you'll be able to do the same here.

    Thanks in advance for the attention and all your help
    Best regards and Happy 4th...
    Rudy

  2. #2
    Join Date
    Oct 2008
    Location
    Pasadena, TX
    Posts
    8

    Default I'v made a change to the code in recent

    I've changed "thetitlestor.com" to "localhost" in all the code and tried it today and still got back an error message, but that is all it says in the browser window, "error" that's it....Still struggling with this...any help would be appreciated.

  3. #3
    Join Date
    Nov 2006
    Location
    Sydney, Australia
    Posts
    4,944

    Default

    Try replacing

    mysql_error();

    with

    echo mysql_error();

    so that the error message gets written out.

  4. #4
    Join Date
    Oct 2008
    Location
    Pasadena, TX
    Posts
    8

    Default Made some head way...

    Want to say thanks to felgall... made that "echo" change and that clear things up. cuddos felgall. Got my first successful registration.

    Now I've got another page at the same test login web callled mainlogin.php which allows the customer to take info just registered and login. The mainlogin.php sends the submitted login info to a php page called checklogin.php

    The connection this time is not the problem, I get an error message like this

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/thetitl1/public_html/Test Login Web/checklogin.php on line 62
    Wrong Username or Password.

    This is the code for http://www.thetitlestor.com/Test%Log...checklogin.php

    </head>

    <body>

    <?php

    echo mysql_error();

    $host="localhost"; // Host name

    $username="thetitl1_ttsprez"; // Mysql username

    $password="test"; // Mysql password

    $db_name="thetitl1_Custreg"; // Database name

    $tbl_name="custlogon"; // Table name

    // Connect to server and select database.

    mysql_connect("localhost", "thetitl1_ttsprez", "test")or die("cannot connect");

    mysql_select_db("thetitl1_Custreg")or die("cannot select DB");

    echo mysql_error();

    //username, and password sent from form

    $username=$_POST['username'];

    $password=$_POST['passwordl'];


    // To protect MySQL injection (more detail about MySQL injection)

    $username = stripslashes($username);

    $password = stripslashes($password);


    $username = mysql_real_escape_string($username);

    $password = mysql_real_escape_string($password);


    $sql="SELECT * FROM $tbl_name WHERE username'=$username' and password'=$password' ";

    $result=mysql_query($sql);

    // Mysql_num_row is counting table row

    $count=mysql_num_rows ($result);

    // If result matched $username and $password, table row must be 1 row

    if($count==1)

    {

    // Register $username, $password, and redirect to file "login_success.php"

    session_register("username");

    session_register("password");

    header("location:login_success.php");

    }

    else {

    echo "Wrong Username or Password";

    }

    ?>

    </body>


    I'm currently researching a fix in the code to see if I can find what's wrong, but if someone sees something that makes life easier, I'd appreciate it..I'm sure it has something to do with how the query is being posted to request confirmation from the database, but I'm not familiar enough with php or mysql yet to figure it out...

    Wish me luck, but any help may be just that...Thanks

  5. #5
    Join Date
    Oct 2008
    Location
    Pasadena, TX
    Posts
    8

    Default

    By the way this is what the code is for line 62...

    $result=mysql_query($sql);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •