I have a slightly strange error (shown below)
This is the code in my login.php file
<form action="loginScript.php" method="post">
<input class="center" type="text" name="username" placeholder="Username" required>
<br>
<input class="center" type="password" name="password" placeholder="Password" required>
<br>
<input class="center" type="submit" value="Login">
</form>
My loginScript.php file uses var_dump($_POST).
Remove name="username" and retype it. Did you copy and paste the code from somewhere? Probably your editor does not show hidden special characters.
Related
I'm trying to create a login page in php.
I got the form and the login verificaion works fine but when i go to my index.php which is my log in page, the login credentials are auto filled with unwanted credentials like below.
Whereas my login paage should look like this..
My form is as below:
<form action="check_login.php" method="post">
<label id="uname">User Name: </label><input type="text" placeholder="Enter Username" name="uname" required="required"> <br>
<label id="psw">Password: </label><input type="password" placeholder="Enter Password" name="psw" required="required"> <br> <br>
<button type="submit" name="login">Login </button>
</form>
When I use type=text it works fine..
I've also tried autocomplete="off", but it doesn't work...
What am I doing wrong? I'm a newbie... Please help me...
change
<input type="text" placeholder="Enter Username" name="uname" required="required">
with
<input type="text" placeholder="Enter Username" name="uname" required="required" autocomplete="off" />
it is browser feature to auto fill the form
"Autofilling" a form is a browser feature. You can turn it off for a form using the autocomplete attribute (setting it to off). Change your form to
<form action="check_login.php" method="post" autocomplete="off">
<label id="uname">User Name: </label><input type="text" placeholder="Enter Username" name="uname" required="required"> <br>
<label id="psw">Password: </label><input type="password" placeholder="Enter Password" name="psw" required="required"> <br> <br>
<button type="submit" name="login">Login </button>
</form>
There might be cases where autocomplete="off" is set, but the browser still fills in your form details. The "trick" is to set autocomplete to an invalid value, like autocomplete="kerbholz".
I got it...removed the user from saved logins from my browser.... And it works fine...
How do I send information from a HTML page to a php page which then makes a connection to a database?
This is my code so far on my website: http://jsfiddle.net/xiiJaMiiE/wNraL/
<h1>
<div id=signin>
<input type="text" name="textbox1" value="Username" onfocus="if
(this.value==this.defaultValue) this.value='';" size="19%" height="50"/></br>
<input type="password" name="password" value="Password" onfocus="if
(this.value==this.defaultValue) this.value='';" size="19%" height="50"/>
</div>
</h1>
Thanks in advance!
Replace your h1 element (you don't have a heading so you shouldn't say you do) with a form element.
Give it an action attribute that specifies the URL of the PHP program you want to submit the data to.
Since you are sending authentication data, add a method attribute that to POST the data.
<form action="signin.php" method="POST">
<div id=signin>
<label>
Username
<input type="text" name="username">
</label>
<label>
Password
<input type="password" name="password">
</label>
</div>
</form>
The data will then be available to PHP via $_POST['field_name_here'].
<div id=signin>
<form action="connection.php" method="POST">
<input type="text" name="username" value="Username" onfocus="if (this.value==this.defaultValue) this.value='';" size="19%" height="50"/>
<br>
<input type="password" name="password" value="Password" onfocus="if (this.value==this.defaultValue) this.value='';" size="19%" height="50"/>
</form>
</div>
You can access these passed variables in the conneciton.php file with $_POST['username'] and $_POST['password'].
you should set the action attribute to a file that will process form data (eg process. php) and pass form data to your database using $_POST('filedName') on submitting the form.
I am sending form data through POST, but the corresponding POST variables are not set, and do not.
Also, when I store POST data into local PHP variables, I seem to be unable to use those variables. (Once I resolve the first issue, I have a feeling I will be able to user the variables too.)
My error messages output by the second page (see below) is:
Notice: Undefined variable: postUsername in (...somepath)\scripts\create-member.php on line 10
(Form page) :
<form action="scripts/create-member.php" method="POST">
<input type="text" name"username" value="" placeholder="User Name"> <br />
<input type="password" name"password" value="" placeholder="Password"> <br />
<input type="password" name"passwordConfirm" value="" placeholder="Confirm Password"> <br />
<!-- ?type email or type text -->
<input type="email" name"email" value="" placeholder="Email" autofocus> <br />
<input type="submit" name="submitRegistration" value="Register!">
</form>
(Second page) scripts\create-member.php:
<?php
//!proper way to declare variables obtained from POST.
// Data from form "register.php"
if ( isset($_POST['username']) ) {
$postUsername = $_POST['username'];
}
echo $postUsername; // <-- this is line 10
?>
I've tried using isset() for the submit button too, but that didn't solve the problem.
I've simplified the code by a lot here, and ran it testing it too.
In your html code, you have missed = for name
name="username"
Instead of name"username"
Here's your fixed code.
<input type="text" name="username" value="" placeholder="User Name"> <br />
<input type="password" name="password" value="" placeholder="Password"> <br />
<input type="password" name="passwordConfirm" value="" placeholder="Confirm Password"> <br />
<!-- ?type email or type text -->
<input type="email" name="email" value="" placeholder="Email" autofocus> <br />
the ploblem is not at register.php
you can try to write like this:
if ( isset($_POST['username']) ) {
$postUsername = $_POST['username'];
echo $postUsername;
}
I had a similar problem posting to an index.php file in a folder.
<form id="register" name="register" method="POST" action="/register">
// BROKEN
all $_POST vars were empty until I added a trailing forward slash to the form post action
<form id="register" name="register" method="POST" action="/register/">
// WORKS
Forgive the title, this is the best way I can think to word my issue.
Basically, I have a html form inside some php code, but I need to include javascript functions (with parameters specified) inside the form. But I have an issue with the single and double quote marks escping the php code. See below:
echo'<form id="create_booking_form" onsubmit="return false;">
<div>Student Name: </div>
<input id="students_name" type="text" onfocus="emptyElement('status')" onkeyup="restrict('students_name')" maxlength="30">
<div>Parents Name: </div>
<input id="parents_name" type="text" onfocus="emptyElement('status')" onkeyup="restrict('parents_name')" maxlength="30">
<div>Parents Email Address: </div>
<input id="parents_email" type="text" onfocus="emptyElement('status')" onkeyup="restrict('parents_email')" maxlength="100">
<div>Booking Time: </div>
<input id="booking_time" type="text" onfocus="emptyElement('status')" onkeyup="restrict('booking_time')" maxlength="8">
<div>Comments / Questions: (max 255 characters)</div>
<input id="comments" type="text" onfocus="emptyElement('status')" onkeyup="restrict('comments')" maxlength="255">
<div>Password: </div>
<input id="password" type="password" maxlength="16">
<br /><br />
<button id="createbookingbtn" onclick="createbooking()">Submit your booking</button>
<span id="status"></span>
</form>
</div>
</div>';?>
My issue is for example: onkeyup="restrict('students_name')"
If i use single quote to specify 'student_name' it escapes the echo command form the php code. If i use double quotes it escapes the restrict() function...
What can I do?
Much appreciated
Is anyone able to help me out here?
If your string is created with ''s, you can print a ' character by escaping it: \', and if it's created with "'s, then you can print it by escaping it to \".
In your situation, however, I wouldn't do either. I'd just end the PHP tag and start it again:
?>
<form id="create_booking_form" onsubmit="return false;">
<div>Student Name: </div>
<input id="students_name" type="text" onfocus="emptyElement('status')" onkeyup="restrict('students_name')" maxlength="30">
<div>Parents Name: </div>
<input id="parents_name" type="text" onfocus="emptyElement('status')" onkeyup="restrict('parents_name')" maxlength="30">
<div>Parents Email Address: </div>
<input id="parents_email" type="text" onfocus="emptyElement('status')" onkeyup="restrict('parents_email')" maxlength="100">
<div>Booking Time: </div>
<input id="booking_time" type="text" onfocus="emptyElement('status')" onkeyup="restrict('booking_time')" maxlength="8">
<div>Comments / Questions: (max 255 characters)</div>
<input id="comments" type="text" onfocus="emptyElement('status')" onkeyup="restrict('comments')" maxlength="255">
<div>Password: </div>
<input id="password" type="password" maxlength="16">
<br /><br />
<button id="createbookingbtn" onclick="createbooking()">Submit your booking</button>
<span id="status"></span>
</form>
</div>
</div>
<?php
But what when I want the HTML content to be in a variable?
Just use an output buffer.
ob_start();
?>
<p>Some HTML</p>
<?php
$html = ob_get_clean();
I would place the javascript in an external file, and have the php place the link to that file instead.
Put a \ in front of the quote to escape:
echo'<form id="create_booking_form" onsubmit="return false;">
<div>Student Name: </div>
<input id="students_name" type="text" onfocus="emptyElement(\'status\')" onkeyup="restrict(\'students_name\')" maxlength="30">
etc
You can escape your quotes by adding a single backslash before them..
i have created a custom popup login box. and use form settings like that
<form action="<?php bloginfo('url'); ?>/wp-login.php?redirect_to=<?php echo urlencode($_SERVER['REQUEST_URI']); ?>" method="post" autocomplete="off">
and i use input feilds like that
<input id="login_username" name="user_name" type="text" value="" class="pop-input surfix" /><span id="placeholder_user_login">Username</span>
<input id="login_password" name="user_password" type="password" value="" class="pop-input" /><span id="placeholder_user_pass">Password</span>
<input id="register" type="submit" value="Login" class="popup-login-btn" />
but it redirecting to wp-login.php except it should process the login and redirect to the pages where from user started login.
please guide me how can i fix this.
thank you all
actually the issue was with the name element of the input field.
When i check the wp-login.php page i discover the wordpress changes the name of input fields.
<input id="login_username" name="user_name"
<input id="login_password" name="user_password"
to
<input id="login_username" name="log"
<input id="login_password" name="pass"
So i just simply replace the names and all issues were sorted out.
Thank you all