Hi,
I'm trying to run validation to ensure that when a membership number is added or updated, it is not the same as any others. I'm already stopping it (as per sxooter's instructions) at a SQL level by making the field 'unique', but obviously people don't want to see a dirty great mysql_error message!
Here is the code which runs if the form is submitted:
<?php
require_once('../sypphp/sypcms/DbConnector.php');
$errorlist = array();
$id = $_POST['id'];
$title = $_POST['title'];
$salutation = $_POST['salutation'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$dobday = $_POST['dobday'];
$dobmonth = $_POST['dobmonth'];
$dobyear = $_POST['dobyear'];
$memstatus = $_POST['memstatus'];
$memtype = $_POST['memtype'];
$joinday = $_POST['joinday'];
$joinmonth = $_POST['joinmonth'];
$joinyear = $_POST['joinyear'];
$expday = $_POST['expday'];
$expmonth = $_POST['expmonth'];
$expyear = $_POST['expyear'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$memnum = $_POST['memnum'];
$email = $_POST['email'];
$oxevents = $_POST['oxevents'];
$scotevents = $_POST['scotevents'];
$allevents = $_POST['allevents'];
$jobsbulletin = $_POST['jobsbulletin'];
$mobtel = $_POST['mobtel'];
$daytel = $_POST['daytel'];
$evetel = $_POST['evetel'];
$company = $_POST['company'];
$position = $_POST['position'];
$department = $_POST['department'];
$companyrep = $_POST['companyrep'];
$college = $_POST['college'];
$course = $_POST['course'];
$collegerep = $_POST['collegerep'];
$notes = $_POST['notes'];
//validate the fields
if (trim($_POST['firstname']) == '') {$errorlist[] = 'You have not entered a First Name';}
if (trim($_POST['surname']) == '') {$errorlist[] = 'You have not entered a Surname';}
if (trim($_POST['address1']) == '') {$errorlist[] = 'You have not entered an Address/Streetname/number';}
if (trim($_POST['postcode']) == '') {$errorlist[] = 'You have not entered a Postcode';}
if (trim($_POST['memnum']) == '') {$errorlist[] = 'You have not assigned a membership number';}
if (trim($_POST['email']) == '') {$errorlist[] = 'You have not entered an email address';}
if (!checkdate($_POST['dobmonth'], $_POST['dobday'], $_POST['dobyear'])){$errorlist[] = 'Please enter a valid Date of Birth';}
if (!checkdate($_POST['joinmonth'], $_POST['joinday'], $_POST['joinyear'])){$errorlist[] = 'Please enter a valid Join Date';}
if (!checkdate($_POST['expmonth'], $_POST['expday'], $_POST['expyear'])){$errorlist[] = 'Please enter a valid Expiry Date';}
$connector = new DbConnector();
$memnumquery = "SELECT COUNT(*) WHERE memnum ='$memnum'";
$checkmemnum = $connector->query($memnumquery);
if (mysql_num_rows($checkmemnum) > 0){ echo 'Memnum taken' ;}
if (sizeof ($errorlist) == 0)
{ //if no problems perform SQl query to inster/update
?>
The problem I'm having is that I get told that mysql_num_rows is an invalid resource, but I can't work out why. I'm guessing that for some reason it's not connecting to the db correctly, but I've already connected to the db earlier in the script to pull through values to populate the update script. If this is the case, i'd guess that either I'm probably putting the new DbConnector line in the wrong place, but I've tried putting it in nearer the top of the above script.
Could somebody please put me out of my misery!?
Thanks!