teejayy1013 Posted February 26, 2008 Share Posted February 26, 2008 Hey guys, i have a quick question that i can't seem to figure out. I'm trying to make an email sign-up where whenever people fill out their information, it gets stored in a mysql table named ComputerClub. I want to make sure though, that people can't sign up for the club more than once with the same email address. Is there a way I can query the ComputerClub database and check the entire email address column and see if the email appears already? This is my current script but its not working and im not even sure if im on the right path. mysql_select_db("ComputerClub"); $query="SELECT EmailAddress FROM ComputerClub where EmailAddress={$_POST['EmailAddress']}"; $result=mysqli_query($dbc,$query); $row=mysqli_fetch_array($result, MYSQLI_ASSOC); $SQLPassword=$row['EmailAddress']; echo $SQLPassword; Link to comment https://forums.phpfreaks.com/topic/93021-php-to-check-mysql-database/ Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 Hey guys, i have a quick question that i can't seem to figure out. I'm trying to make an email sign-up where whenever people fill out their information, it gets stored in a mysql table named ComputerClub. I want to make sure though, that people can't sign up for the club more than once with the same email address. Is there a way I can query the ComputerClub database and check the entire email address column and see if the email appears already? This is my current script but its not working and im not even sure if im on the right path. mysql_select_db("ComputerClub"); $query="SELECT EmailAddress FROM ComputerClub where EmailAddress={$_POST['EmailAddress']}"; $result=mysqli_query($dbc,$query); $row=mysqli_fetch_array($result, MYSQLI_ASSOC); $SQLPassword=$row['EmailAddress']; echo $SQLPassword; Your using 2 different forms of MySQL functions, I don't use MySQLi, but either way I think it would be better to pick one and stick with it. Second of all I never had any luck running a SQL Query line with an array, but that might just be a personal issue. but if you want a simple function to return if a email exists or not have your SQL already set up with mysql_connect("localhost", "user", "password") or die ("MySQL Error: ".mysql_error()); mysql_select_db("ComputerClub"); run this line: <?php $email = $_POST['email']; if(mysql_num_rows(mysql_query("SELECT EmailAddress FROM ComputerClub where EmailAddress='$email'"))) { //What to do if true } else { //What to do if false } That should work, if not: if(emailexists($_POST['email']) { //What to do if true } else { //What to do if false } And have this somewhere outside of any function or if brackets: <?php function emailexists($email) { $sql = mysql_query("SELECT EmailAddress FROM ComputerClub where EmailAddress='$email'"); return mysql_num_rows($sql); } If it gets no results it will return 0; thus weighing it as false Link to comment https://forums.phpfreaks.com/topic/93021-php-to-check-mysql-database/#findComment-476578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.