Cyberspace Posted April 9, 2008 Share Posted April 9, 2008 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/100350-query-help/ Share on other sites More sharing options...
Daniel0 Posted April 9, 2008 Share Posted April 9, 2008 You would use AND and not && in SQL. Quote Link to comment https://forums.phpfreaks.com/topic/100350-query-help/#findComment-513161 Share on other sites More sharing options...
writer Posted April 9, 2008 Share Posted April 9, 2008 Nice catch, Daniel0. Quote Link to comment https://forums.phpfreaks.com/topic/100350-query-help/#findComment-513172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.