Jump to content

PHP to check mysql database


teejayy1013

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.