1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Variable error message not displaying

Discussion in 'PHP' started by Colbyt, Mar 4, 2006.

  1. #1
    I am trying to debug a script that I did not write. I have little experience with PHP. The script is working fine but the proper error message is not displayed when I create an error situation. It looks like the author had the same problem and took the easy way out.

    This snippet establishes the variable value for $serror. It seems like the <br>'s do not belong there but maybe that is permissible.

    }else if($submit2) {
    		if(!ereg("^[A-Za-z0-9_]{1,16}$",$susername)) {
    			$serror="Invalid username! Use no more than 15 characters and only letters, numbers, and underscores.<br>"; 
    		}
    		$this->c=@mysql_query("select username from users where username='$susername'");
    		$this->d=mysql_fetch_object($this->c);
    		if(is_object($this->d)) { $serror="Username is already in use<br>"; }
    		$this->c=@mysql_query("select username from pending where username='$susername'");
    		$this->d=mysql_fetch_object($this->c);
    		if(is_object($this->d)) { $serror="Username is already in use<br>"; }
    		echo "<h3>Signup for a New Account Step 3</h3>";
    		if (!$serror) {
    PHP:
    The next snippet is where the variable $serror should be diplayed. Please note that I added the "Hello World" part of this snippet to trace the code.

    I thought a variable could only be displayed with the echo tag. At any rate this isn't working because what you get on all errors is:

    $serror Hello World
    ?>
    			<form method=post>
    			<?=$table2?>
    			<tr align=center>
    				<td colspan=3>$serror <font color=red>Hello World</font><p></td>
    			</tr>
    PHP:

    Any insight appreciated.

    Colbyt
     
    Colbyt, Mar 4, 2006 IP
  2. Andrewaclt

    Andrewaclt Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you need to put php tags around the $error so try <? echo $error ?>
     
    Andrewaclt, Mar 4, 2006 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3

    Thank you very much!

    That took care of the problem.

    Colbyt
     
    Colbyt, Mar 4, 2006 IP