I want to insert userid, password & the e-mail address entered in a Form by
users in a database but only after ensuring that the userid & the e-mail
address doesn't exist in the database in order to avoid duplicate userids &
e-mail addresses. This is what I have done:

<?php
$connectionString=odbc_connect("DSNName","sa","");
$query1="SELECT Email,UserID, FROM tblName";
$execQuery1=odbc_do($connectionString,$query1);

While(odbc_fetch_row($execQuery1)){
 $email=odbc_result($execQuery1,1);
 $userid=odbc_result($execQuery1,2);

echo $email,"\n",$userid;
;
If($_POST['email']==$email){
echo("E-Mail Address Already Exists !!! Please Use A Different E-Mail
Address !!!");
}
Else If($_POST['uid']==$userid){
echo("UserID Already Exists !!! Please Use A Different UserID !!!");
}
Else{
odbc_close($connectionString);
$connectionString=odbc_connect("DSNName","sa","");
$query2="INSERT INTO tblName(Email,UserID,Password)
VALUES('$_POST[email]','$_POST[uid]','$_POST[pwd]')";
$execQuery2=odbc_do($connectionString,$query2);
odbc_close($connectionString);

echo "Your UserID is",$_POST['uid'],"<br>";
echo "Your Password is ",$_POST['pwd'];
}
}

When the above code gets executed, if either the userid or the e-mail
address already exists in the database, this record is not only inserted in
the database but the error message which should be displayed under such
circumstances is shown as well where as what I want is that only the error
message be displayed & the record should not be inserted in the database.
Also the output shows the following Warning message:

Warning: odbc_fetch_row(): 2 is not a valid ODBC result resource in
C:\Inetpub\wwwroot\Insert.php

which points to the While statement. What is wrong with the code? Also in
the warning message, where from is 2 coming? The line echo
$email,"\n",$userid; which should show all the userids & the e-mail
addresses existing in the database, shows only the first 2 records instead
!!! Is this where from the warning message is showing 2? Where is the error
in the above code?

Thanks,

Arpan



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to