PHP/MySQL & Control Structures -> if (mysql_query())

From: Date: Wed, 21 Mar 2001 04:28:56 +0000
Subject: PHP/MySQL & Control Structures -> if (mysql_query())
Groups: php.general 
Request: Send a blank email to php-general+get-44871@lists.php.net to get a copy of this message
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? 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"]); } } 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 -- Mike Gifford, OpenConcept Consulting, http://openconcept.ca Offering everything your organization needs for an effective web site. Latest Featured Site: http://www.lornenystrom.org/ No problem can be solved with the same thinking that created it - A.Einstein

« previous php.general (#44871) next »