Jump to content

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


Recommended Posts

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);

?>

Are you sure you want to use mysql functions and not mysqli functions? With mysql functions the connection identifier is the second parameter and is not required. With mysqli functions, it's the first parameter and is required.

 

Ken

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.