Guteman Posted August 4, 2006 Share Posted August 4, 2006 Hey All,Im in the middle of creating a private messanging system for my client system, but I have hit an issue. Here is my problem, I have a form and one of the fields is "recipient." Now, what im trying todo is to make sure the recipient(pm) = login(client). This is what I tried todo.[code]$checkname = mysql_query("SELECT login FROM clients WHERE login"); $checkname= mysql_fetch_array($checkname);[/code][code]else if($checkname != $_POST['recipient']) { $error_message .= '<p class="failure">Error: Username does not exist.</p>'; }[/code]its not working, I think its a problem with my mysql query, can someone help?Thanks,Paul G. Quote Link to comment Share on other sites More sharing options...
bpops Posted August 4, 2006 Share Posted August 4, 2006 your code seems a bit incomplete.. I see an "else if" but no "if".. Quote Link to comment Share on other sites More sharing options...
trq Posted August 4, 2006 Share Posted August 4, 2006 Your missing part of your WHERE clause. The syntax should be something like...[code]SELECT fld FROM tbl WHERE fld = 'value';[/code] Quote Link to comment Share on other sites More sharing options...
Guteman Posted August 4, 2006 Author Share Posted August 4, 2006 Let me clarify... I tried this, but still nothing[code]$checkname = mysql_query("SELECT login FROM clients WHERE login='$_POST[recipient]'"); $checkname= mysql_fetch_array($checkname); if(strlen($_POST['recipient']) <= 0) { $error_message .= '<p class="failure">Error: You did not enter a Recipient.</p>'; } else if($checkname != $_POST['recipient']) { $error_message .= '<p class="failure">Error: Username does not exist.</p>'; }[/code]I knew it was the while, but I cant figure out what to use. Quote Link to comment Share on other sites More sharing options...
trq Posted August 4, 2006 Share Posted August 4, 2006 [quote]I knew it was the while, but I cant figure out what to use.[/quote]What while? Quote Link to comment Share on other sites More sharing options...
Guteman Posted August 4, 2006 Author Share Posted August 4, 2006 sorry for spamLet me use an exampleI want to send a message to Guteman, one of my clients. I want to make sure I typed in the right name before the message is sent, or it sends an $error_message.I want $checkname to become Guteman or any other client I have.I meant WHERE not while, sorry Quote Link to comment Share on other sites More sharing options...
bpops Posted August 4, 2006 Share Posted August 4, 2006 can you change[code]$checkname = mysql_query("SELECT login FROM clients WHERE login='$_POST[recipient]'"); [/code]to[code]$checkname = mysql_query("SELECT login FROM clients WHERE login='$_POST[recipient]'") or die ("MySQL query error."); [/code]?That way we know wether or not the query is executing Quote Link to comment Share on other sites More sharing options...
bpops Posted August 4, 2006 Share Posted August 4, 2006 you also might want to try changing$_POST[recipient] to $_POST['recipient']i dunno if those quotes matter a whole lot or not. Quote Link to comment Share on other sites More sharing options...
nethnet Posted August 4, 2006 Share Posted August 4, 2006 $checkname is an array, yet you are treating it as a string in your if statement. Add a key called 'login' to it.[code]$checkname['login'][/code] Quote Link to comment Share on other sites More sharing options...
Guteman Posted August 4, 2006 Author Share Posted August 4, 2006 thanks alot.. it worked. Quote Link to comment Share on other sites More sharing options...
bpops Posted August 4, 2006 Share Posted August 4, 2006 [quote author=nethnet link=topic=102936.msg409311#msg409311 date=1154661065]$checkname is an array, yet you are treating it as a string in your if statement. Add a key called 'login' to it.[code]$checkname['login'][/code][/quote]Hehe I always try to help but I'm never the one who sees the real problem :P 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.