Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validate User problem

Status
Not open for further replies.

columbo1977

Programmer
May 9, 2006
49
GB
Good Evening

I have created a server behaviour in Dreamweaver to check if a username exists when someone registers at the site.

When i click submit i get the following errors?

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in c:\webserver\phpdev5\ on line 8

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\webserver\phpdev5\ on line 9

the code for the checking is below

<?php
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="denied_u.html";
$loginUsername = $_POST['username'];
$LoginRS__query = "SELECT Username FROM users WHERE Username='" . $loginUsername . "'";
mysql_select_db($database_null, $null);
$LoginRS=mysql_query($LoginRS__query, $null) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);

//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}

Can anyone help as to why the errors come up.

Cheers

Columbo1977
 
I believe its complaining about the parameters you are passing to the [blue]mysql_select_db[/blue] function either

$database_null, or $null, does not contain the correct information.

PHP.net Online Manual said:
mysql_select_db
Description
bool mysql_select_db ( string database_name [, resource link_identifier] )

Sets the current active database on the server that's associated with the specified link identifier. Every subsequent call to mysql_query() will be made on the active database.
Parameters

database_name

The name of the database that is to be selected.
link_identifier

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.[/red]

Make sure there is a call to mysql_connect before mysql_select_db, and that you pass the correct parametrs to the function.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Situation has changed, please see code below.

<?php require_once('Connections/DB.php'); ?><?php
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="denied_u.html";
$loginUsername = $_POST['username'];
$LoginRS__query = "SELECT Username FROM users WHERE Username='" . $loginUsername . "'";
$conn = mysql_connect('127.0.0.1','root','');
mysql_select_db($database_DB, $conn);
$LoginRS=mysql_query($LoginRS__query, $conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect"); <----------------------------------------------------Line18
exit;
}
}

and the error mesage i now get is

Warning: Cannot add header information - headers already sent by (output started at c:\webserver\phpdev5\ in c:\webserver\phpdev5\ on line 18

Does anyone know why?
 
Check for any output (either html before the opening <?php bracket, a space or enter before it, or print or echo statements in the file and all included files) before the header call. Header needs to happen before any other output.
 
Excellent, thanks for that, I had a space at the beginning.
All working ok now

Cheers

Columbo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top