Jump to content

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


dgilby

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.