dgilby Posted June 2, 2010 Share Posted June 2, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/203637-warning-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/ Share on other sites More sharing options...
foxsoup Posted June 2, 2010 Share Posted June 2, 2010 You're got the variables in the mysql_query function the wrong way around. Try replacing this: $data = mysql_query($dbc, $query); with this: $data = mysql_query($query, $dbc); Quote Link to comment https://forums.phpfreaks.com/topic/203637-warning-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1066660 Share on other sites More sharing options...
kenrbnsn Posted June 2, 2010 Share Posted June 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203637-warning-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1066662 Share on other sites More sharing options...
dgilby Posted June 2, 2010 Author Share Posted June 2, 2010 Thanks I will try that. My server doesn't have mysqli functionality. They are apparently working on it. then I will change the code Quote Link to comment https://forums.phpfreaks.com/topic/203637-warning-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1066671 Share on other sites More sharing options...
dgilby Posted June 2, 2010 Author Share Posted June 2, 2010 Thanks foxsoup really appreciate that. All the documentation that I seen was for the way I had it. Quote Link to comment https://forums.phpfreaks.com/topic/203637-warning-mysql_query-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-1066865 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.