christofurr Posted June 26, 2007 Author Share Posted June 26, 2007 Would help if you explained your code, ReDucTor. Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 I give up. I'm posting one last suggestion, take it or leave it. <?php if ($result = mysql_query("SELECT Nickname FROM Froobs WHERE Nickname = '{$_POST['nick']}' || Email_Address = '{$_POST['email']}'")) { if (!mysql_num_rows($result)) { /*Execute database input*/ } } ?> And... one last time. Integers DO NOT get surrounded in quotes. eg; <?php $a = 2; // not $a = "2"; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Wow, I am suprised at half you guys code, and disappointed. Come off it. This op doesn't listen when you make suggestions anyway. Look at my suggestions! Quote Link to comment Share on other sites More sharing options...
christofurr Posted June 26, 2007 Author Share Posted June 26, 2007 No, I'm watching all suggestions. I'd just like to understand why mine doesn't work. How can I learn from my mistakes if I just toss out my scripts and copy somebody elses? Now, I'd like ReDucTor to explain his code, and somebody to explain why the query in thorpe's code requires '{}' around the $_POST variable. :-X Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Well, a few things. For starters, you never check to see if your queries where successfull before trying to use the results. I can tell you now, that your queries both should fail because you fail to wrap your values (eg; $_POST['email') in quotes. I said this quite a few replies ago. (Ignored) I also told you that the cortrect syntax for embeding arrays into double quoted string is to surround them in {} curly braces. (Ignored) Quote Link to comment Share on other sites More sharing options...
christofurr Posted June 26, 2007 Author Share Posted June 26, 2007 Thanks, thorpe. That reply wasn't ignored. I missed it because mkoga posted right after. Quote Link to comment Share on other sites More sharing options...
christofurr Posted June 26, 2007 Author Share Posted June 26, 2007 How's this? <?php $takenick = mysql_query("SELECT Nickname FROM Froobs WHERE Nickname = '$nicktrim'"); $takemail = mysql_query("SELECT Email_Address FROM Froobs WHERE Email_Address = '{$_POST['email']}'"); if (mysql_num_rows($takenick) >= 1) {$error = "A1";} if (mysql_num_rows($takemail) >= 1) {$error = "A2";} if ($error != "A1" && $error != "A2") { /*Execute database input*/ } ?> Quote Link to comment Share on other sites More sharing options...
christofurr Posted June 26, 2007 Author Share Posted June 26, 2007 Tested and working. One last issue before I hit the Topic Solved button. In my form, I specified that the input values be the input values of the previous submission attempt using the $_POST variable. This works fine for all but some input fields in which the previous input is displayed with a backslash in the middle of it. This happens only in the case where the input includes an apostrophe or a quotation mark. How do I prevent the addition of a backslash? <?php $recqtrim = trim($_POST["recq"]); echo " <input type=\"text\" name=\"recq\" value=\"" . $recqtrim . "\" size=\"35\" maxlength=\"75\" /> "; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Ok... at minimum you need this to do it using your approuch. Comments explain why. <?php // ps, ive taken the liberty of formatting your code more traditionaly. // if you ever want to program larger projects with others, the way you // format your code will NOT be accepted. $takenick = mysql_query("SELECT Nickname FROM Froobs WHERE Nickname = '$nicktrim'") or die(mysql_error()); // you want to trap errors here, helps for debugging $takemail = mysql_query("SELECT Email_Address FROM Froobs WHERE Email_Address = '{$_POST['email']}'") or die(mysql_error()) // same again. // you'll need to initialize $error to something. Otherwise, if you dont find any results you will get an error in your last if statement. $error = 0; // no need to check for >=1, just check if true. if (mysql_num_rows($takenick)) { $error = "A1"; } if (mysql_num_rows($takemail)) { $error = "A2"; } if ($error != "A1" || $error != "A2") {// you want to check if $error equals A1 or A2, not if it equals both because it can't. /*Execute database input*/ } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 About the slashes. $recqtrim = stripslashes(trim($_POST["recq"])); Quote Link to comment Share on other sites More sharing options...
christofurr Posted June 26, 2007 Author Share Posted June 26, 2007 Great. One thing, though. I'm checking to see if $error is not equal to A1 or A2. If I check for either, somebody may be able to register a duplicate nickname with a new email address or a duplicate email address with a new nickname. Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Great. One thing, though. I'm checking to see if $error is not equal to A1 or A2. If I check if either isn't true, somebody may be able to register a duplicate nickname with a new email address or a duplicate email address with a new nickname. Sorry... my bad. Quote Link to comment Share on other sites More sharing options...
christofurr Posted June 26, 2007 Author Share Posted June 26, 2007 Thanks again! Quote Link to comment 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.