Click to See Complete Forum and Search --> : Validate User problem Dreamweaver


columbo1977
05-28-2006, 05:39 PM
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\www\ccc_website\registration.php on line 8

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\webserver\phpdev5\www\ccc_website\registration.php 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

abou.hmed
05-28-2006, 07:01 PM
you have used the $database_Null paramerter without declaring it,so you should declare your Database Name and password as second variable

columbo1977
05-29-2006, 03:45 AM
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\www\ccc_website\registration.php:1) in c:\webserver\phpdev5\www\ccc_website\registration.php on line 18

Does anyone know why?

abou.hmed
05-29-2006, 04:54 AM
ok this error is when u have an html or any echo in the same page with header , in your case m try 2 see if they are any space before <?php in the first line

columbo1977
05-29-2006, 05:01 AM
yes mate there was a space, thanks for the help.

Cheers

Columbo1977