www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP & MySQL noob error.

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Location
    Gujarat, India.
    Posts
    35

    PHP & MySQL noob error.

    i m nt much pro in php & mysql but i find some scripts on web & understood(at least i think so) and now trying to run'em. I uploaded'em to server but they aren't working.

    I think i shall tell you that website is (desired to) run on free server, the free domain has been registered and they are telling it will be active in 72 hours, till i am trying to try my code (i am given facility to preview). SO I want to know that..
    1. Is there problem in script? if yes, where? (I don't think bcz, its from reliable website)
    2. Is there problem in username & password, because i am reading (ref. errors below) "ACCESS DENIED"?
    3. Do server needs to active to public before i can check this? I don't think so....because i think we can also make this work without internet as html pages.... can't we?Well leave it.
    4. At lease i also request to give me technique to make log in system.
    Sorry for any mistakes,Thanks in advance. Here are Scripts & Errors.

    First Script named conf.inc.php :
    PHP Code:
    <?php
    $db_user 
    "u123_admin"// Username
    $db_pass "admin1right"// Password
    $db_database "u123_userbase"// Database Name
    $db_host ""// Server Hostname
    $db_connect mysql_connect ($db_host$db_user$db_pass); // Connects to the database.
    $db_select mysql_select_db ($db_database); // Selects the database.
     
    function form($data) { // Prevents SQL Injection
       
    global $db_connect;
       
    $data ereg_replace("[\'\")(;|`,<>]"""$data);
       
    $data mysql_real_escape_string(trim($data), $db_connect);
       return 
    stripslashes($data);
    }
    ?>
    The second script named register.php:

    PHP Code:
    <?php
    include("conf.inc.php"); // Includes the db and form info.
    if (!isset($_POST['submit'])) { // If the form has not been submitted.
        
    echo "<form action=\"register.php\" method=\"POST\">";
        echo 
    "<table>";
        echo 
    "<tr>";
        echo 
    "<td colspan=\"2\">Register:</td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td width=\"50%\">Email:</td><td width=\"50%\"><input name=\"email\" size=\"18\" type=\"text\" />";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";
        echo 
    "</tr>";
        echo 
    "</table>";
        echo 
    "</form>";
    } else { 
    // The form has been submitted.
        
    $username form($_POST['username']);
        
    $password md5($_POST['password']); // Encrypts the password.
        
    $email form($_POST['email']);
     
        if ((
    $username == "") || ($password == "") || ($email == "")) { // Checks for blanks.
            
    exit("There was a field missing, please correct the form.");
        }
     
        
    $q mysql_query("SELECT * FROM `users` WHERE username = '$username' OR email = '$email'") or die (mysql_error()); // mySQL Query
        
    $r mysql_num_rows($q); // Checks to see if anything is in the db.
     
        
    if ($r 0) { // If there are users with the same username/email.
            
    exit("That username/email is already registered!");
        } else {
            
    mysql_query("INSERT INTO `users` (username,password,email) VALUES ('$username','$password','$email')") or die (mysql_error()); // Inserts the user.
            
    header("Location: login.php"); // Back to login.
        
    }
    }
    mysql_close($db_connect); // Closes the connection.
    ?>
    When i try to run this i receive errors:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'u123_admin'@'localhost' (using password: YES) in /home/u123/public_html/conf.inc.php on line 6

    Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'root'@'localhost' (using password: NO) in /home/u123/public_html/conf.inc.php on line 7

    Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/123/public_html/conf.inc.php on line 7

  2. #2
    Either mysql is not running or mysql socket is in different place.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,615
    You need to find out from your hosting provider (or your control panel there) what database host to use and what user/password credentials to use there -- or perhaps even if your account there includes MySQL at all?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Oct 2012
    Location
    Gujarat, India.
    Posts
    35
    Thanks, guys! I solved it, problem was in hostname, when i check server's faq, i see that they told to look in MySQL Database menu for hostname. I got it, thanks for your help. Sorry for that mistake.... .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles