Caladan Posted May 29, 2006 Share Posted May 29, 2006 Hi everybody, I'm a real noob at php but i try to muddle through as best I can.Recently I had cause to make a webpage that includes a petition on it and i set it ut up like this.I have a webpage with multiple form fields on it, one for name, address, email and comment.I use php to connect to a mysql db that has all those fields in it and the script the checks if name and email exists, if they dont it inserts the form fields to a new entry, if they do exist it redirects to another page.My problem is I seem to mess up the checking of the two fields part. I thought I'd been clever and set it up so that it checks if both fields exits in a given row but users can not add just a name without and email adress. Any help here would be great, just keep in mind I am fairly new to php.I will include my code here:<?phpinclude "./scripts/config.php";include "./scripts/opendb.php";if(isset($_POST['add'])){ $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname,$conn) or die("Could not connect to db"); $navn = $_POST['navn']; $adresse = $_POST['adresse']; $email = $_POST['email']; $kommentar = $_POST['kommentar']; $query = "SELECT * FROM $table WHERE navn = '$navn' OR email = '$email'"; $result = mysql_query($query); $numR = mysql_num_rows($result); if($numR >= 1) { header('Location: [a href=\"http://www.somesite.com/denied.html');\" target=\"_blank\"]http://www.somesite.com/denied.html');[/a] } else { $query = "INSERT INTO $table (navn,adresse,email,kommentar) VALUES ('$navn','$adresse','$email','$kommentar')"; mysql_query($query,$conn) or die('Error, insert query failed'.mysql_error()); mysql_close(); header('Location: [a href=\"http://www.somesite.com/thankyou.html');\" target=\"_blank\"]http://www.somesite.com/thankyou.html');[/a] }}After this i have another else statement that prints the form and such and after that there is a ?>So the code analyzer in zend studio tells me it should be well formatted.Caladan Link to comment https://forums.phpfreaks.com/topic/10739-checking-to-see-if-name-and-emailadress-already-exists/ Share on other sites More sharing options...
fenway Posted May 30, 2006 Share Posted May 30, 2006 Well, you're using an OR -- sounds like you want both fields to be checked together. Link to comment https://forums.phpfreaks.com/topic/10739-checking-to-see-if-name-and-emailadress-already-exists/#findComment-40171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.