Page 1 of 1

SQL

Posted: Thu Jun 27, 2002 10:14 pm
by prasadharischandra
hai,
this is not working any sugestions!!!


$add_user="insert into usr_info (usr_name,usr_passw,usr_type,usr_location,usr_full_name,usr_address,
usr_contact)values (\"$username\",\"$password\",\"$type\",\"$location\",\"$fname\",\"$address\",\"$contactno\"
)";




$checkuser=mysql_query("select * from usr_info where usr_name='$username'")
or die(mysql_error());
$available=mysql_num_rows($checkuser)
or die(mysql_error());
if ($available==0)
{
mysql_query($add_user) or die(mysql_error());
echo "successfully";}
else{

echo "soory Already Added";

}
?>

no errors showing and else part is working properly and if part not working any suggestions. that is i can't insert to data into the database

Posted: Fri Jun 28, 2002 1:42 am
by twigletmac
Try:

Code: Select all

$add_user="INSERT INTO usr_info (usr_name, usr_passw, usr_type, usr_location, usr_full_name, usr_address, usr_contact) VALUES ('$username', '$password', '$type', '$location', '$fname', '$address', '$contactno')";
echo $add_user;
To check that your SQL statement looks like you would expect it to.

Mac

SQL

Posted: Fri Jun 28, 2002 3:09 am
by prasadharischandra
twigletmac wrote:Try:

Code: Select all

$add_user="INSERT INTO usr_info (usr_name, usr_passw, usr_type, usr_location, usr_full_name, usr_address, usr_contact) VALUES ('$username', '$password', '$type', '$location', '$fname', '$address', '$contactno')";
echo $add_user;
To check that your SQL statement looks like you would expect it to.

Mac
prasad: i'' ll try using same code problem is if Mysql_num_rows are not there it will work

Posted: Sat Jun 29, 2002 5:44 am
by hob_goblin
try:

Code: Select all

$add_user="insert into usr_info  (usr_name,usr_passw,usr_type,usr_location,usr_full_name,usr_address, usr_contact) values("$username","$password","$type","$location","$fname","$address","$contactno" )"; 




$checkuser=mysql_query("select * from usr_info where usr_name='$username'") 
or die(mysql_error()); 
$available=mysql_num_rows($checkuser) 
or die(mysql_error()); 
if (empty($available)) { 
mysql_query($add_user)
 or die(mysql_error()); 
echo "successfully";
} else { 
echo "sorry, already added."; 
}