User name always have default value
Moderator: General Moderators
-
tanvirtonu
- Forum Commoner
- Posts: 35
- Joined: Wed Oct 17, 2007 9:15 am
User name always have default value
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) )
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
What does your code look like?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 .
Re: User name always have default value
isset() and empty() are PHP functions. You can look them up in the PHP manual and learn what they do:tanvirtonu wrote:What is the difference between-
If ( $variable ) and If ( isSet($variable) ) and if ( empty($variable) )
http://us.php.net/manual/en/function.isset.php
Re: User name always have default value
Here are a few examples of how these instances may act differently than each other and differently than you may have expected:tanvirtonu wrote: I have another question. What is the difference between-
If ( $variable ) and If ( isSet($variable) ) and if ( empty($variable) )
$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.
-
tanvirtonu
- Forum Commoner
- Posts: 35
- Joined: Wed Oct 17, 2007 9:15 am
Re: User name always have default value
sorry to be late ...Here is my simple login form which always fetch default value from somewwhere.....
here is the index.html -
here is the login.php
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>
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
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:
to this:
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
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>
Code: Select all
Username : <input type="text" name="username" value=""><br>
Password : <input type="password" name="password" value=""><br>
Best wishes
-
tanvirtonu
- Forum Commoner
- Posts: 35
- Joined: Wed Oct 17, 2007 9:15 am
Re: User name always have default value
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
No I can not replicate your problem. It is a little confusing but it could be two things:phphelpme wrote:I have tested your code in xampp also just to make sure and I can not replicate your issue.
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
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.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..
Re: User name always have default value
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. lolcalifdon wrote:This is why I never use Dreamweaver. The server can't set default values for your variables.
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
-
tanvirtonu
- Forum Commoner
- Posts: 35
- Joined: Wed Oct 17, 2007 9:15 am
Re: User name always have default value
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
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.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..
Re: User name always have default value
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
-Greg
-
tanvirtonu
- Forum Commoner
- Posts: 35
- Joined: Wed Oct 17, 2007 9:15 am
Re: User name always have default value
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.
ThANX EVERBODY FOR THE HELP.
Re: User name always have default value
Good thinking, twinedev.