Jump to content

Comparing a db query with user input.


ibuprofen

Recommended Posts

The code below is a function that checks to see if an email address exists in a database, if so it alerts the user. The db has one table and one field. It works fine when there is ONE record! However, if there are > 1 it doesn't work. How can I step through each record and compare it to what the user entered? Of course,  $_POST is the user's value and the db record is the $myAddy value.

 

<?php

function emailLookup()

{

include ('file:///Library/WebServer/Documents/re_connect_scripts/emailLookup.php');

while ($row = mysqli_fetch_array($result))

{

extract ($row);

$myAddy = $addy;

}

if ($_POST["add_email"] == $myAddy)

{

global $lookupError;

$lookupError = 'This email address is already on the list.';

global $counter;

$counter++;

}

else

{

return;

}

}

?>

Link to comment
Share on other sites

your searching for the number of times there is a mail address in  the DB?

<?php
function fetchNum($sql){


	$result = mysql_query($sql);
	$num_rows = mysql_num_rows($result);	

	if($num_rows < 1){
		$result = 0;
	} else {
		$result = $num_rows;
	}

	return $result; 
}

$sql = "select * from tablename where fieldname ='".$_POST['REQUEST VAR']."' ";

if(fetchNum($sql) >= 1))
{
        echo "exists";
}

else 
{
        echo "doest exist";
}

?>

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.