Jump to content

Mysql query () error


bravo14

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
https://forums.phpfreaks.com/topic/124157-mysql-query-error/
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
https://forums.phpfreaks.com/topic/124157-mysql-query-error/#findComment-641154
Share on other sites

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.