Help with error - newbie

Discussion in 'Databases' started by dgilby, Jun 1, 2010.

  1. #1
    Hi I get the following error.

    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource on line 24

    Could someone take a look at this and provide an explaination. I also tried the SQL statement in phpadmin and it works fine.

    This is my first script and I desparately need a second pair of eyes.


    ** CODE **
    <?php

    // require_once('connectionvariables.php');

    // connect to the database
    $dbc = mysql_connect('localhost', 'dereyorg', 'nespephi', 'dereyorg_Test');

    // $db = mysql_select_db('dereyorg_Test');

    // check if variables are set when submit button is pressed
    if (isset($_POST['submit'])) {
    $firstname = mysql_real_escape_string($dbc, trim($_POST['firstname']));
    $lastname = mysql_real_escape_string($dbc, trim($_POST['lastname']));
    $email = mysql_real_escape_string($dbc, trim($_POST['email']));
    $username = mysql_real_escape_string($dbc, trim($_POST['username']));
    $password = mysql_real_escape_string($dbc, trim($_POST['password']));
    }

    // mysql validation
    if (!empty($firstname) && !empty($lastname) && !empty($email) && !empty($username) && !empty($password))

    // make sure username isn't already taken
    $query = "SELECT * FROM members WHERE username = '$username'";
    $data = mysql_query($dbc, $query);

    if (mysql_num_rows($data) == 0) {
    // if username is unique, insert into database
    $query = "INSERT INTO members (firtname, lastname, email, username, password) VALUES ('$firstname', '$lastname', '$email', '$username', SHA('$password'))";

    mysql_query($dbc, $query);

    echo '<p>Your account has been successfully created. You\'re now ready to <a href="login.html">Login</a></p>';

    mysql_close($dbc);
    exit;
    }
    else {
    // an account already exists for this username, display error
    echo '<p class="error">An account already exists for this username. Please select a different username</p>';
    $username = "";
    }

    mysql_close($dbc);
    ?>
     
    dgilby, Jun 1, 2010 IP
  2. saviola

    saviola Peon

    Messages:
    17
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi, you have an error in function`s arguments. The fourth parameter "dereyorg_Test" is boolean (default - bool $new_link = false).

    For details and examples visit htp://php.net.
     
    saviola, Jun 3, 2010 IP
  3. dgilby

    dgilby Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Savoila

    Appreciate it.

    D
     
    dgilby, Jun 3, 2010 IP