Page 1 of 2
User name always have default value
Posted: Thu Aug 18, 2011 6:22 am
by tanvirtonu
Hello I m new to php. I made a simple html form with two textboxes- username and password but when I run them they always have some default values- admin and a password. Where did they get this default value. I didnt put any value in them. I use xampp as php-mysql server .
I have another question. What is the difference between-
If ( $variable ) and If ( isSet($variable) ) and if ( empty($variable) )
Re: User name always have default value
Posted: Thu Aug 18, 2011 9:15 am
by Celauran
tanvirtonu wrote:Hello I m new to php. I made a simple html form with two textboxes- username and password but when I run them they always have some default values- admin and a password. Where did they get this default value. I didnt put any value in them. I use xampp as php-mysql server .
What does your code look like?
Re: User name always have default value
Posted: Thu Aug 18, 2011 12:44 pm
by califdon
tanvirtonu wrote:What is the difference between-
If ( $variable ) and If ( isSet($variable) ) and if ( empty($variable) )
isset() and
empty() are PHP
functions. You can look them up in the PHP manual and learn what they do:
http://us.php.net/manual/en/function.isset.php
Re: User name always have default value
Posted: Thu Aug 18, 2011 1:54 pm
by Dorin85
tanvirtonu wrote:
I have another question. What is the difference between-
If ( $variable ) and If ( isSet($variable) ) and if ( empty($variable) )
Here are a few examples of how these instances may act differently than each other and differently than you may have expected:
$variable = false; //boolean "false"
if($variable) //If the variable is a boolean value equal to "false" then the if-statement will evaluate to false
if(isset($variable)) //This will evaluate as true since the variable IS set, "isset" doesn't care if the value is "false"
A case where "empty()" may act differently:
$variable = ""; //"empty()" considers this variable to be empty while "isset()" considers this variable to be set (both will return true)
Also "if($variable)" will return an error if the variable is not set. If you use if(@$variable) it will prevent displaying an error.
Those are the subtle differences between the 3.
Re: User name always have default value
Posted: Sat Aug 20, 2011 8:25 am
by tanvirtonu
sorry to be late ...Here is my simple login form which always fetch default value from somewwhere.....
here is the
index.html -
Code: Select all
<html>
<h1> USER LOG IN PAGE </h1>
<form action='login.php' method='POST'>
User name<input type='text' name= 'username'> <br>
Password <input type='password' name= 'password'> <br>
<input type='submit' value='Submit'>
</form>
</html>
here is the login.php
Code: Select all
<?php
session_start();
$user= $_POST['username'];
$password= $_POST['password'];
if ($user && $password)
{
$connect = mysql_connect("localhost","tanvir","angela") or die ("couldn't connect db");
mysql_select_db('classicmodels') or die ("couldn't find db");
$query= mysql_query("SELECT * FROM user WHERE name= '$user' ") or die ( mysql_error());
$num_rows= mysql_num_rows ($query);
if($num_rows != 0)
{
$row=mysql_fetch_array($query);
if( $password== $row['password'])
{
echo "YOU ARE LOGGED IN ! <a href='member.php'>Go to</a> member page";
$_SESSION['username']=$user;
}
else die ("password doesn't match");
}
else die ("user doesn't exist");
}
else die ("enter username and password");
?>
Re: User name always have default value
Posted: Sat Aug 20, 2011 9:00 am
by phphelpme
Looking at your coding there is nothing wrong with it. It works just fine. I would suggest placing a value="" on your inputs just to see if this solves your problem.
I have tested your code in xampp also just to make sure and I can not replicate your issue.
So change:
Code: Select all
User name<input type='text' name= 'username'><br>
Password <input type='password' name= 'password'><br>
to this:
Code: Select all
Username : <input type="text" name="username" value=""><br>
Password : <input type="password" name="password" value=""><br>
At least this way you are telling xampp to show nothing as the default value for your input fields and see if this stops causing the problem.
Best wishes
Re: User name always have default value
Posted: Sat Aug 20, 2011 1:00 pm
by tanvirtonu
Its really strange..still not woking with value="" ,what the hell are they coming from..I first encountered this with Dreamweaver. I used Dreamweaver's built-in framework code which made that user login page automatically but when I run it, it gets that default value - admin as username and some password. I think it has to do with something else, not my coding. Maybe server or smthing else..do u have the same problem with my code..
Re: User name always have default value
Posted: Sat Aug 20, 2011 1:06 pm
by phphelpme
phphelpme wrote:I have tested your code in xampp also just to make sure and I can not replicate your issue.
No I can not replicate your problem. It is a little confusing but it could be two things:
You said you used dreamweaver to generate the code for you so could that be an issue with Dreamweaver still trying to do something with it as it runs on your server or it has to do with Xampp but I have standard installation of Xampp and I can not replicate your issues. It works just fine for me.
Best wishes
Re: User name always have default value
Posted: Sat Aug 20, 2011 1:16 pm
by califdon
tanvirtonu wrote:Its really strange..still not woking with value="" ,what the hell are they coming from..I first encountered this with Dreamweaver. I used Dreamweaver's built-in framework code which made that user login page automatically but when I run it, it gets that default value - admin as username and some password. I think it has to do with something else, not my coding. Maybe server or smthing else..do u have the same problem with my code..
This is why I never use Dreamweaver. Evidently you are still using some code generated by DW which you haven't shown us. The server can't set default values for your variables. Search
ALL of your code for the words you are seeing ('admin' and 'password'). Someplace you
will find lines that assign those values to the variable names. That's why nobody else can replicate the behavior, because we don't have the same code that you have. And please don't post hundreds of lines of Dreamweaver code here; you can search for it just as easily as we can.
Re: User name always have default value
Posted: Sat Aug 20, 2011 4:11 pm
by phphelpme
califdon wrote:This is why I never use Dreamweaver. The server can't set default values for your variables.
I could not agree more. I hate Dreamweaver for putting in all its crap as usual. It's great for the design button yeah for noobs but whats happened to editing the file in say notepad, and click save but have it open in the browser at the same time. There you have your preview. lol
There must be something that we are not being shown or some function like using Dreamweaver Server Site Management or something like that which is effecting your default values.
Best wishes
Re: User name always have default value
Posted: Sat Aug 20, 2011 5:37 pm
by tanvirtonu
Thnx evrybody...you all ended in argument abt dreamweaver but I said it ALSO happened with DW first time, NOT that I m STILL using DW code..I posted the simple code that is fetching the values from smwhere and that is certainly as u can see NOT DW code. There is NOTHING that I am not showing, this single snippet of code is doing all these problems...pls have another look at my code...That is IT..nothing more nothing less..
Re: User name always have default value
Posted: Sat Aug 20, 2011 6:07 pm
by califdon
tanvirtonu wrote:Thnx evrybody...you all ended in argument abt dreamweaver but I said it ALSO happened with DW first time, NOT that I m STILL using DW code..I posted the simple code that is fetching the values from smwhere and that is certainly as u can see NOT DW code. There is NOTHING that I am not showing, this single snippet of code is doing all these problems...pls have another look at my code...That is IT..nothing more nothing less..
So you're saying that even before you submit the form, there are values in the input fields of the form? I don't see how that's possible, but then what was the purpose of showing us the PHP code?? If that is the entire content of your html file, I would say that you are not running that same file when you experience the behavior you describe. And it has nothing to do with PHP, because there is no PHP in that file. It is often the case that you have 2 different files with the same name, but in different subfolders, and you are editing a different file from the one that you are viewing. I've done that many times. It sounds to me like that's what is happening in your case.
Re: User name always have default value
Posted: Sat Aug 20, 2011 6:13 pm
by twinedev
Have you at one point been to the same page and told your browser to remember the form entries (or using a browser that painfully will over guess it?) I know I have seen firefox auto fill in something that was saved even AFTER i typed in something different. Try a different browser that you haven't used for this and/or a separate computer.
-Greg
Re: User name always have default value
Posted: Sat Aug 20, 2011 7:48 pm
by tanvirtonu
Thanx twinedev, u r right. I removed all the histories from firefox and set it to" never remember history"..and walla! the problem is gone...
ThANX EVERBODY FOR THE HELP.
Re: User name always have default value
Posted: Sat Aug 20, 2011 8:07 pm
by califdon
Good thinking, twinedev.