ahvceo Posted May 22, 2009 Share Posted May 22, 2009 Hi All, I have a form on a php page and when the user name is aready in use I send a message to the User Name input box. I would like to be able to indicate the message is an error by coloring it red, or better yet changing the background color of the input box. I have searched the web for several hours but I can not find anything that works if(mysql_num_rows($chk_user) > 0) { $errorMsg .= AFF_SI_USEREXISTS.'<br>'; $_POST['ausername'] = 'Name Already Taken, Try Another'; } The "ausernane" refers to the input box where the error message is displayed. Can anyone tell me how to make something appear in red to show that an error message is being displayed? Thanks ahvceo Quote Link to comment Share on other sites More sharing options...
ionik Posted May 22, 2009 Share Posted May 22, 2009 if(mysql_num_rows($chk_user) > 0) { $errorMsg .= AFF_SI_USEREXISTS.'<br>'; $_POST['ausername'] = '<span style="color: red;">Name Already Taken, Try Another</span>'; } Quote Link to comment Share on other sites More sharing options...
jsschmitt Posted May 22, 2009 Share Posted May 22, 2009 Tack the html code into the php... '<div style="color:red">Name Already Taken, Try Another</div>'; Quote Link to comment Share on other sites More sharing options...
Dathremar Posted May 22, 2009 Share Posted May 22, 2009 These guys beat me to it Quote Link to comment Share on other sites More sharing options...
ahvceo Posted May 23, 2009 Author Share Posted May 23, 2009 Hi Guys, I tried your code and the results are attached in a screen shot. As you can see part of the code is placed in the input box and the rest of it after the input box. I think what needs to be done is address the attributes of the input box which this code does not do. I haven't the foggiest idea od how to do that. Thanks ahvceo [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Masna Posted May 23, 2009 Share Posted May 23, 2009 Hi Guys, I tried your code and the results are attached in a screen shot. As you can see part of the code is placed in the input box and the rest of it after the input box. I think what needs to be done is address the attributes of the input box which this code does not do. I haven't the foggiest idea od how to do that. Thanks ahvceo Don't fill this name-already-in-use error message into an input box. Place it next to or above the input box. Quote Link to comment Share on other sites More sharing options...
ch1326 Posted May 23, 2009 Share Posted May 23, 2009 how about trying if(mysql_num_rows($chk_user) > 0) { $errorMsg .= AFF_SI_USEREXISTS.'<br>'; $_POST['ausername'] = '<font color = 'red'>Name Already Taken, Try Another</font>'; } I hope it will work Quote Link to comment Share on other sites More sharing options...
ahvceo Posted May 24, 2009 Author Share Posted May 24, 2009 Hi Guys, I have tried everything you suggested without success. I am pretty sure I need to do something at the html level where the inputbox is being displayed. I thought the following code would work but I cannot get the syntax straight. The server keeps puking on the first "echo" line. Can someone help me out here? Thanks ahvceo <tr> <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000">Choose Password: *</font></b></td> <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000"> <? if ($errorMsg == AFF_SI_USEREXISTS) echo "<input type="text" name="ausername" maxlength="12" size=30 background-color=#FA1B00 value="<?=$_POST['ausername']?>"; else echo "<input type="text" name="ausername" maxlength="12" size=30 value="<?=$_POST['ausername']?>"; ?> </font></b></td> </tr> [/cvode] Quote Link to comment Share on other sites More sharing options...
eRott Posted May 24, 2009 Share Posted May 24, 2009 <tr> <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000">Choose Password: *</font></b></td> <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000"> <?php if ($errorMsg == AFF_SI_USEREXISTS) { echo '<input type="text" name="ausername" maxlength="12" size="30" background-color="#FA1B00" value="'.$_POST['ausername'].'">'; } else { echo '<input type="text" name="ausername" maxlength="12" size="30" value="'.$_POST['ausername'].'">'; } ?> </font></b></td> </tr> EDIT: By the way, what is AFF_SI_USEREXISTS? Is that supposed to be a function? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted May 24, 2009 Share Posted May 24, 2009 You're missing basic html... This echo "<input type="text" name="ausername" maxlength="12" size=30 background-color=#FA1B00 value="<?=$_POST['ausername']?>"; should be echo "<input type="text" name="ausername" maxlength="12" size=30 style="background-color: #FA1B00;" value="<?=$_POST['ausername']?>"; Quote Link to comment Share on other sites More sharing options...
eRott Posted May 24, 2009 Share Posted May 24, 2009 You're missing basic html... This echo "<input type="text" name="ausername" maxlength="12" size=30 background-color=#FA1B00 value="<?=$_POST['ausername']?>"; should be echo "<input type="text" name="ausername" maxlength="12" size=30 style="background-color: #FA1B00;" value="<?=$_POST['ausername']?>"; Your missing the fact that use cannot use double quotes inside of an echo which uses double quotes unless you escape them first using \. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted May 24, 2009 Share Posted May 24, 2009 So escape them...or use a single quote... echo '<input type="text" name="ausername" maxlength="12" size=30 style="background-color: #FA1B00;" value="' . $_POST['ausername'] . '">'; Rocket surgery... Quote Link to comment Share on other sites More sharing options...
.josh Posted May 24, 2009 Share Posted May 24, 2009 EDIT: By the way, what is AFF_SI_USEREXISTS? Is that supposed to be a function? assuming its not a syntax error, it's a constant. Quote Link to comment Share on other sites More sharing options...
Goafer Posted May 25, 2009 Share Posted May 25, 2009 You're missing basic html... This echo "<input type="text" name="ausername" maxlength="12" size=30 background-color=#FA1B00 value="<?=$_POST['ausername']?>"; should be echo "<input type="text" name="ausername" maxlength="12" size=30 style="background-color: #FA1B00;" value="<?=$_POST['ausername']?>"; Wouldn't if just be easier to use: echo "<input type="text" name="ausername" maxlength="12" size=30 bgcolor= "#FA1B00" value="<?=$_POST['ausername']?>"; rather than introducing inline styles? Quote Link to comment Share on other sites More sharing options...
ahvceo Posted May 28, 2009 Author Share Posted May 28, 2009 Hi All, Sorry I haven't been back sooner but I got tied up. Seems i just cannot fet as much done in a day as I used to and I haven't learned that yet. Anyhow, I cannot get the text in the input box to be red no matter what I do, but in the process of trying I learned that I don't want to do that anyway because then the error message can get in the system as a user name. Take a lot od work to get around that so I have just put an error message at the top of the screen and everything works fine now, Thanks for all your time and suggestions. They were a big help to me, ahvceo 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.