Jump to content

Mysql query () error


bravo14
 Share

Recommended Posts

Hi guys

 

I have included a part of the code I am trying to use, I am basically trying to see if a username is already in use before adding the record to the database.

<?php
include ("includes/connector.php");
//*assign names to variables
$username = $_POST[username];
$first_name = $_POST[firstname];
$surname = $_POST[surname];
$email = $_POST[email];
$password = $_POST[password];
$address1 = $_POST[address1];
$address2 = $_POST[address2];
$address3 = $_POST[address3];
$address4 = $_POST[address4];
$postcode = $_POST[postcode];
//*check if username already exists
$cxn = mysql_connect($host, $user, $passwd, $dbname) or die ("Couldn't connect to server");
$sql = "SELECT username FROM customers WHERE username = '$username'";
$result = mysql_query($cxn,$sql) or die ("Query died: user name"); //line 145
$num = mysql_num_rows($result);

 

The error message I am getting is

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\alhassam\register.php on line 145, I have indicated line 145 above, can anyone point out my error.

 

Cheers

 

Link to comment
Share on other sites

Thanks for that, have made the correction but now I am getting the die error and again can't see anything wrong with the query or execution of it

 

$cxn = mysql_connect($host, $user, $passwd, $dbname) or die ("Couldn't connect to server");
$sql = "SELECT username FROM customers WHERE username = '$username'";
$result = mysql_query($cxn,$sql) or die ("Query died: user name"); //line 145

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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