On Wed, 21 Mar 2001 14:58, Mike Gifford wrote:
> Hello,
>
> I'd like the presense or absense of information within a database to be
> involved in an if statement, however I'm having trouble getting it to
> work.  I've set up the following:
>
> $same_Email_query = mysql_query("SELECT Email FROM phPetition WHERE
> Email='" . $Email  . "'");
> if($same_Email_query){
> $error = 1;
> $error_html .= "This email \"" . $Email . "\" has already been used to
> sign the petition.<br><br>\n";
> }
>
> In this case, I'd like the mysql_query to search the database for the
> instance of the submitted $Email and if there is a duplicate entry in
> the database, then I'd like the if() statement to return an error (as
> lised above).
>
> Any idea what I'm doing wrong?

$same_Email_query is a pointer to a result set from the query and will 
always be true if the query succeeded - where succeeded means something 
like 'returned 0 or more matching rows'

What you need to do is check how many matching rows are returned by your 
query; if there are zero rows, the value doesn't exist in the database.

> In a similar way I'm trying to query the database for instances of the
> same IPAddress:
>
> $sameIP_query = mysql_query("SELECT
> FirstName,LastName,CityState,IPAddress FROM phPetition WHERE
> IPAddress='" . getenv('REMOTE_ADDR')  . "' ORDER BY LastName"); if
> ($sameIP_query) {
>
> echo "The following individuals have signed this petition from the same
> IP: " . getenv('REMOTE_ADDR');
>     while ($sameIP_array = mysql_fetch_array($sameIP_query)) {
>     echo "<LI>" . stripslashes($individuals_array["FirstName"]) . " " .
> stripslashes($individuals_array["LastName"]) . " from " .
> stripslashes($individuals_array["CityState"]);
>   }
> }

Shouldn't $individuals_array[ be $sameIP_array[ ? Consider using extract; 
if nothing else it makes code easier to read :-)

> If the database already has entries which have been submitted from the
> same IPAddress, I'd like to have those names and numbers listed.
>
> The previous version of this code is published and available here:
>       http://openconcept.ca/guide-petition.phtml
>
> Thanks.
>
> Mike

-- 
David Robley                        | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet                            | http://auseinet.flinders.edu.au/
            Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to