Jump to content

Best way to check if data exist


lJesterl

Recommended Posts

I'm wondering the best method to use to do the following.

 


say if($whatever){

do this

}else{

do this

}

 

i want $whatever basicly to be this. I want to check to see if the input name='emailx' exist as email in table GCuser.

 

Here is the code I used

 


$checkemail=mysql_query("SELECT email FROM GCuser WHERE email='$emailx'");
$ce=mysql_fetch_array($checkemail);

if($emailx == $ce[email]){

//display error

}else{

//execute mysql query
}

 

it works however if they dont change the emailx input field then it errors for them, or if they change the emailx input field from lets say [email protected] to [email protected] it errors because [email protected] doesnt exist. I hope someone understand what im trying to ask lol

Link to comment
https://forums.phpfreaks.com/topic/60702-best-way-to-check-if-data-exist/
Share on other sites

Doesnt work 100%

 

If i leave it along when submiting and the email being the default value for the email say [email protected] then it errors or if i change it to anything that exist in the database, however when i change to something that doesnt exist then it works. The only problem left would be if i leave it default and i try to submit it with no change. Is there a way to ignore my error if its my own name?

 

this is my code

 


$checkemail=mysql_query("SELECT email FROM GCuser WHERE email='$emailx' LIMIT 1");

if(mysql_num_rows($checkemail) == 1){

        include("$dir[functions]/error.php");
        display_error("Email is already in use please try another email.<br>");

}else{

$query1=mysql_query("DELETE FROM playerprofile WHERE alias='$ui[alias]'");

$query=mysql_query("insert into playerprofile (alias,xboxcard,aim,yahoo,msn,icq,xfire,skype,xbox360,ps3,wii,location,connection,relationship,orientation,drink,smoker,religion,education,interests) values('$ui[alias]','$xboxcard','$aim','$yahoo','$msn','$icq','$xfire','$skype','$xbox360','$ps3','$wii','$location','$connection','$relationship','$orientation','$drink','$smoker','$religion','$education','$interests')");

$query2=mysql_query("UPDATE users SET logo='$avatar2' WHERE id='$ui[id]'");
$query5=mysql_query("UPDATE users SET email='$emailx' WHERE id='$ui[id]'");
$query4=mysql_query("UPDATE GCuser SET email='$emailx' WHERE username='$ui[alias]'");
$query4=mysql_query("UPDATE GCuser SET aim='$aim' WHERE username='$ui[alias]'");
$query4=mysql_query("UPDATE GCuser SET yahoo='$yahoo' WHERE username='$ui[alias]'");
$query4=mysql_query("UPDATE GCuser SET msn='$msn' WHERE username='$ui[alias]'");
$query4=mysql_query("UPDATE GCuser SET skype='$skype' WHERE username='$ui[alias]'");


}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.