I am working in php/mySQL and I have added the INSERT RECORD behavior. I have
added some additional code to verify that a username is not already taken
before I allow a new insert record action. What I need to do is check the
'administration' table to verify that the username is not already taken. The
code shown below is for a simple record insertion in php/mySQL plus I have
added some code (in bold). I am getting two warning messages: Warning:
mysql_num_rows(): supplied argument is not a valid MySQL result resource in
c:\inetpub\wwwroot\05training\create_account.php on line 42 Warning: Cannot
modify header information - headers already sent by (output started at
c:\inetpub\wwwroot\05training\create_account.php:4 2) in
c:\inetpub\wwwroot\05training\create_account.php on line 67 Line 42 is: if
(mysql_num_rows($Result) == 0) { Line 67 is: header(sprintf('Location: %s',
$insertGoTo)); <?php // insert new record function
GetSQLValueString($theValue, $theType, $theDefinedValue = '',
$theNotDefinedValue = '') { $theValue = (!get_magic_quotes_gpc()) ?
addslashes($theValue) : $theValue; switch ($theType) { case 'text':
$theValue = ($theValue != '') ? ''' . $theValue . ''' : 'NULL'; break;
case 'long': case 'int': $theValue = ($theValue != '') ?
intval($theValue) : 'NULL'; break; case 'double': $theValue =
($theValue != '') ? ''' . doubleval($theValue) . ''' : 'NULL'; break;
case 'date': $theValue = ($theValue != '') ? ''' . $theValue . ''' :
'NULL'; break; case 'defined': $theValue = ($theValue != '') ?
$theDefinedValue : $theNotDefinedValue; break; } return $theValue; }
$editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= '?' . htmlentities($_SERVER['QUERY_STRING']); } if
((isset($_POST['MM_insert'])) &amp;&amp; ($_POST['MM_insert'] ==
'accountForm')) { // verify that username is not already taken $Query =
'SELECT * FROM administration WHERE username=$_POST[username]'; if
(mysql_num_rows($Result) == 0) { // Now setup the new user since apparently
no one else has this username // insert new record $insertSQL =
sprintf('INSERT INTO administration (username, password, userGroup,
regFirstName, regLastName, regTitle, regCompany, regCity, regState, regZip,
regEmail, regPhone) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
GetSQLValueString($_POST['username'], 'text'),
GetSQLValueString($_POST['password'], 'text'),
GetSQLValueString($_POST['userGroup'], 'text'),
GetSQLValueString($_POST['regFirstName'], 'text'),
GetSQLValueString($_POST['regLastName'], 'text'),
GetSQLValueString($_POST['regTitle'], 'text'),
GetSQLValueString($_POST['regCompany'], 'text'),
GetSQLValueString($_POST['regCity'], 'text'),
GetSQLValueString($_POST['regState'], 'text'),
GetSQLValueString($_POST['regZip'], 'text'),
GetSQLValueString($_POST['regEmail'], 'text'),
GetSQLValueString($_POST['regPhone'], 'text'));
mysql_select_db($database_conn_train, $conn_train); $Result1 =
mysql_query($insertSQL, $conn_train) or die(mysql_error()); $insertGoTo =
'account_success.php?regEmail=' . $regEmail; if
(isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo,
'?')) ? '&amp;' : '?'; $insertGoTo .= $_SERVER['QUERY_STRING']; }
header(sprintf('Location: %s', $insertGoTo)); } else { print ('Sorry, this
username is already taken'); die(); } } ?> Any ideas on what is wrong
with the code? Any help is greatly appreciated!