Jump to content

Using inline PHP; <h1><font color="000088">The username <?php '.$username.' ?> already exists";</h1>


IHaveAQuestion

Recommended Posts

ISSUE.
A User enters information into a form.
If the 'username' is already taken, a 'message' in Red and with larger font-size will be returned, for example,
"The username $username already exists."
If the username is 'mattd' then the message should say, "The username mattd already exists."

Within my php application, I have included 'inline html'.
Here is part of the code:

 

....
if (mysql_num_rows($query_run)==1) {
// it will never = more than one because only
//one user will or will not exist
?>

<html>
</body>
<h1><font color="#FF0066">The username <?php echo $username; ?>already exists.</h1>
</body>
</html>

<?php
}else{
//start the registration process
$query = "INSERT INTO `Names` VALUES
....

 

1. At one point I did get this: "The username mattd already exists."
2. But now I only get "The username already exists."
I am not retrieving the $username variable.

 

This screenshot is found here:
http://imgur.com/lIwLZ1G


thanks.

What does this have to do with HTML? This is clearly a PHP problem.

 

You said you don't retrieve the $username variable. My guess is that the code was written a long time ago when the register_globals setting was still around. Back in those days, the PHP core developers thought it's a good idea to automatically create variables from input parameters. For example, if the script was executed with a form parameter called “username”, then PHP would automatically create a $username variable. This quickly turned out to be a major security vulnerability (see the link), so the whole feature was deprecated in 2009 and removed in 2012. But appearently it lives on in your code.

 

Define your variables properly, and the problem will go away.

@jacques1: He may have turned off warnings/errors reporting so to him, the error

//The line below was formatted according to html style he defined
The username 
Notice: Undefined variable: username in <file_path>.php on line 5
already exists.

he is getting just the line

The username already exists

You are right. he may not have defined $username.

 

@IHaveAQuestion: Can you post the full code you wrote? and please write them in code section (using <> icon in this editor)

Archived

This topic is now archived and is closed to further replies.

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