tutoriale photoshop, brushes, patterns, gradient
Site afiliat proiectului Wtricks.com
   
   
  REGULAMENT | Search | Members | Calendar | Help  
 


Post Reply  Post Thread 
mysql_connect[problem]
Author Message
Dynamyc
Activ
*


Posts: 6
Group: Registered
Joined: Jan 2008
Status: Offline
Reputation: 0
Lei: 295.68
Post: #1
mysql_connect[problem]

am facut un script de inregistrare si un script pt conectarea la baza de date care arata cam asa :

Code:
<?php
DEFINE ('DB_USER','root ');
DEFINE ('DB_PASSWORD','blabla');
DEFINE ('DB_HOST','localhost');
DEFINE ('DB_NAME','sitename ');
//realizeaza conexiunea
$dbc=@mysql_connect (DB_HOST,DB_USER,DB_PASSWORD) OR die(mysql_error());
//selecteaza baza de date
@mysql_select_db (DB_NAME) OR die ('Could not connect to database: ' );
// creeaza o functie pt inserarea secventelor escape in date
function escape_data ($data) {
     //contracareaza efectele optiunii Magic Quotes
     if (ini_get('magic_quotes_gpc')) {
         $data= stripslashes($data);
     }
     //verifica daca este disponibila functia mysql_real_escape_string()
     if (function_exists ('mysql_real_escape_string')) {
         global $dbc; // este necesara o conexiune
         $data= mysql_real_escape_string(trim($data),$dbc);
     }
     else {
         $data=mysql_escape_string(trim($data));
     }
     //returneaza valorile, dupa inserarea secventelor escape .
     return $data;
} //sfarsitul functiei
?>


si scriptul de inregistrare:

Code:
<?php # Script 8.7 - register.php
// Send NOTHING to the Web browser prior to the header() line!

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

    require_once ('mysql_connect.php'); // Connect to the db.
        
    $errors = array(); // Initialize error array.
    
    // Check for a first name.
    if (empty($_POST['first_name'])) {
        $errors[] = 'You forgot to enter your first name.';
    } else {
        $fn = escape_data($_POST['first_name']);
    }
    
    // Check for a last name.
    if (empty($_POST['last_name'])) {
        $errors[] = 'You forgot to enter your last name.';
    } else {
        $ln = escape_data($_POST['last_name']);
    }
    
    // Check for an email address.
    if (empty($_POST['email'])) {
        $errors[] = 'You forgot to enter your email address.';
    } else {
        $e = escape_data($_POST['email']);
    }
    
    // Check for a password and match against the confirmed password.
    if (!empty($_POST['password1'])) {
        if ($_POST['password1'] != $_POST['password2']) {
            $errors[] = 'Your password did not match the confirmed password.';
        } else {
            $p = escape_data($_POST['password1']);
        }
    } else {
        $errors[] = 'You forgot to enter your password.';
    }
    
    if (empty($errors)) { // If everything's OK.
    
        // Register the user in the database.
        
        // Check for previous registration.
        $query = "SELECT user_id FROM users WHERE email='$e'";
        $result = mysql_query($query);
        if (mysql_num_rows($result) == 0) {

            // Make the query.
            $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";        
            $result = @mysql_query ($query); // Run the query.
            if ($result) { // If it ran OK.
            
                // Send an email, if desired.
                
                // Redirect the user to the thanks.php page.
                // Start defining the URL.
                $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
                
                // Check for a trailing slash.
                if ((substr($url, -1) == '/') OR (substr($url, -1) == '\') ) {
                    $url = substr ($url, 0, -1); // Chop off the slash.
                }
                
                // Add the page.
                $url .= '/thanks.php';
                
                header("Location: $url");
                exit();
                
            } else { // If it did not run OK.
                $errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.'; // Public message.
                $errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.
            }
                
        } else { // Email address is already taken.
            $errors[] = 'The email address has already been registered.';
        }
                
    } // End of if (empty($errors)) IF.

    mysql_close(); // Close the database connection.
        
} else { // Form has not been submitted.

    $errors = NULL;

} // End of the main Submit conditional.

// Begin the page now.
$page_title = 'FlameClub';
include ('./includes/header.html');

if (!empty($errors)) { // Print any error messages.
    echo '<h1 id="mainhead">Error!</h1>
    <p class="error">The following error(s) occurred:<br />';
    foreach ($errors as $msg) { // Print each error.
        echo " - $msg<br />\n";
    }
    echo '</p><p>Please try again.</p>';
}

// Create the form.
?>
<h2>Register</h2>
<form action="register.php" method="post">
    <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
    <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
    <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"  /> </p>
    <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p>
    <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p>
    <p><input type="submit" name="submit" value="Register" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>


Bun, am incercat pe un host gratuit si dupa ce completez formularul de inregistrare imi apare asta:
Access denied for user 'root '@'localhost' (using password: YES)
am incercat pe hostul de pe calclutaor (Wamp) tot aceasi problema
am incercat sa ma conectez din consola MYSQL m-am gandit ca poate nu e buna parola dar a mers
ce gresesc? nu imi pot da seama ...

02-09-2008 09:45 AM
Find all posts by this user Quote this message in a reply
Aurel63
Aproape expert
********


Posts: 888
Group: Registered
Joined: Dec 2007
Status: Offline
Reputation: 4
Lei: 4015.02
Post: #2
RE: mysql_connect[problem]

DE ce nu incerci pe un forum de programatori? Vezi ca  are dexter forum special pe programare, e de treaba si te poate ajuta.


Mark Twain - "N-am lasat niciodata scoala sa-mi afecteze educatia."
Mark Twain - "Cel mai bun mod de a te inveseli este sa incerci sa inveselesti pe altcineva."
02-09-2008 10:15 AM
Find all posts by this user Quote this message in a reply
casperel
Designer incepator
*****


Posts: 280
Group: Registered
Joined: Oct 2007
Status: Online
Reputation: 0
Lei: 303.15
Post: #3
RE: mysql_connect[problem]

DEFINE ('DB_NAME','sitename '); trebuia DEFINE ('DB_NAME','sitename'); ?


http://www.zuma24.com - Joaca Zuma Online ;)
http://www.movie-crawler.com - A movie a day keeps the weariness away!
http://www.georgejipa.info - Blogging-ul... un continuu calcul matematic!
02-09-2008 10:27 AM
Find all posts by this user Quote this message in a reply
unmicdrac
Banned


Posts: 72
Group: Banned
Joined: Feb 2008
Status: Offline
Lei: 334.78
Post: #4
RE: mysql_connect[problem]

Sigur ai completat corect datele de autentificare la mysql? Care este serverul de mysql, care este baza de date, care este userul si parola pentru aceasta baza de date? Baza de date pe care o folosesti, exista ? Si daca asta e scriptul ala dintr-o carte, nu mai stiu cum naiba se numea ceva cu"Teach yourself mysql&php in 24 hours" parca, vezi ca ai niste tabele de incarcat inainte in baza de date pentru ca scriptul sa functioneze.


Cutest babes of the internet
02-09-2008 03:58 PM
Visit this users website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump:

 

 Invatam Net
Esti nou pe aici? Vorbeste-ne despre tine.
Citeste articole si tutoriale unice.
Ai un site? Iti putem oferi un review.

  Parteneri

  

  

  UNIX, Linux, Programare si Scripting pentru incepatori

  

-->