Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/159257-solved-how-do-i-color-text-in-php/
Share on other sites

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]

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.

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]

<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?

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']?>";

 

 

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 \.

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?

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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