Jump to content

Query Help


Cyberspace

Recommended Posts

Im trying to check whether a record exists in a table called "Walker", the table has the fields "WalkNo" and "MemberRef". I want to check if a record exists, if the WalkNo has the MemberRef already assigned to the WalkNo in the table.

 

I have the following code, the last query is where im having difficulty:

 

if (isset($_POST['submit'])) {  

$error_stat = 0;  
    $MemberRef_message = ''; 
    $Password_message = '';
    $Password2_message = '';
    $User_message = '';
    $Walk_message = '';

    $MemberRef = mysql_real_escape_string(stripslashes($_POST['MemberRef']));
    $Password = mysql_real_escape_string(stripslashes($_POST['Password']));
    
//Error checking  

// MemberRef Check)  
if (!$MemberRef) { 
//Set the error_stat to 1, which means that an error has occurred 
    $error_stat = 1; 

//Set the message to tell the user to enter a username 
    $MemberRef_message = '*Please enter MemberRef*'; 
} 

else if (!ctype_digit($MemberRef)) {  
   $error_stat = 1;  
   $MemberRef_message .= '*MemberRef must be a number*';  
} 

if (!$Password) { 
//Set the error_stat to 1, which means that an error has occurred 
    $error_stat = 1; 

//Set the message to tell the user to enter a username 
    $Password_message = '*Please enter a Password*'; 

}

if (isset($_POST['submit']) && $error_stat == 0) {  


$account = mysql_query("SELECT * FROM members WHERE MemberRef='$MemberRef' &&  Password='$Password'");

if(mysql_num_rows($account) == 0){
         $error_stat = 1;
//Set the message to tell the user MemberRef does not exist 
    $User_message = '*Member does not exist*';
    
if (isset($_POST['submit']) && $error_stat == 0) {  


$account = mysql_query("SELECT * FROM walkers WHERE MemberRef='$MemberRef' &&  WalkNo='$WalkNo'");

if(mysql_num_rows($account) == 1){
         $error_stat = 1;
//Set the message to tell the user MemberRef does not exist 
    $Walk_message = '*Member has already joined this walk*';

        
}
}
}
}
}


?>


<hr class="hr_blue"/></p><font face="Arial" size="3">Join Walk</font><form method="post" class="addwalkerform" action="">   
</font>
<fieldset>
<label for="MemberRef">MemberRef:</label>  
<input name="MemberRef" type="text" id="MemberRef" value="<?php echo $_POST['MemberRef']; ?>"/> 
<span class="redboldtxt"><?php echo "$MemberRef_message";?></fieldset></span>  
</fieldset>

<fieldset>
<label for="Password">Password:</label>  
<input name="Password" type="text" id="Password" value="<?php echo $_POST['Password']; ?>"/> 
<span class="redboldtxt"><?php echo "$Password_message";?></fieldset></span>
<span class="redboldtxt"><?php echo "$Password2_message";?></fieldset></span>

<fieldset> 
<p class="submit"><input type="submit" name="submit" value="Join Walk" />

<span class="redboldtxt"><?php echo "$User_message";?></fieldset></span>

<span class="redboldtxt"><?php echo "$Walk_message";?></fieldset></span>


</fieldset>


</fieldset>
</form>

<?php
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/100350-query-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.