Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to insert my form information into a database that is already created. So far I have:
<form action="insert.php" method="post">
Username:
Password:
Confirm Password:
<input type="submit">
if loops {
send alert and return back to form page; }
</form>
My question is: using this code, will the user information still be sent to the database file if the if loops are activated or will I need an exit statement after every if loop? (I do not want any information sent if the if loops are activated).
Thanks
You need inputs on your form:
<form action="insert.php" method="post">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
Confirm Password: <input type="password" name="confirm">
<input type="submit" name="submit">
</form>
Then on insert.php
if (isset($_POST['submit'])){
$Error = 0;
if (!isset($_POST['username'])){
$Error++;
}
if (!isset($_POST['password'])){
$Error++;
}
if (!isset($_POST['confirm'])){
$Error++;
}
if ($Error > 0){
echo "Error in HTML Validation";
exit;
}
// continue post verification here.
}
You can also validate your form in client-side and it is faster and reduces server load:
<form name="myForm" action="insert.php" method="post" onsubmit="return validateForm()>
Username:
Password:
Confirm Password:
<input type="submit">
</form>
And write a javascript for validating your form:
<script type="text/javaScript">
function validateForm()
{
//Here will be your validation logic
//if input doesn't meet your requirement then return false
var x=document.forms["myForm"]["email"].value;
if(x is not an email address)
return false;
}
}
</script>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I don't know PHP and have downloaded this code that works perfectly fine.
I add this code on top of any *.php file and it makes that page, password protected that only opens up if you type the password which in this case is 1234.
Now, I want to add 3 passwords instead of 1. I just don't know where to edit this code.
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
if($pass=="1234")
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>
<?php
if($_SESSION['password']=="1234")
{
?>
<form method="post" action="" id="logout_form">
<input type="submit" name="page_logout" value="Logout">
</form>
<?php
}
else
{
?>
<form method="post" action="">
<div>Protected Content</div>
<br />
<input type="password" name="pass" placeholder="Type your password">
<input type="submit" name="submit_pass" value="Login">
<br /><br />
<div><?php echo $error;?></div>
</form>
<?php
}
?>
Where should I, add what, to be able to have 3 possible passwords?
For this, you may edit password checking line like this:
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
$available_passwords = ['12345','pass123','myOtherPassword'];
if(in_array($pass,$ava_passwords))
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have an HTML form with three inputs: Make, Year, Mileage.
The conditions are that Make should not be empty, and Year and Mileage must be numeric.
The form submits when the conditions are met.
However, when one of the conditions is not met, I'm using PHP to redirect to the same page and display an error message on the screen. Now when I enter correct values, the form wouldn't submit. Nor does the cancel button redirects it to the previous page.
If I want the form to submit after the error message has been displayed, I have to refresh it and then enter correct values. How can I avoid the refresh?
Here's the code:
<?php
session_start();
require_once "pdo.php";
if (!isset($_SESSION['email']) || strlen($_SESSION['email']) < 1) {
die('Not logged in');
}
if (isset($_POST['cancel'])) {
header("Location: view.php");
return;
}
if (isset($_POST['make']) && isset($_POST['year']) && isset($_POST['mileage'])) {
if (strlen($_POST['make']) < 1) {
$_SESSION['failure'] = "Make is required";
header("Location: add.php");
return;
}
else {
if (!is_numeric($_POST['year']) || !is_numeric($_POST['mileage'])) {
$_SESSION['failure'] = "Mileage and year must be numeric";
header("Location: add.php");
return;
}
else {
$sql = "INSERT INTO autos(make, year, mileage)
VALUES(:mk, :yr, :ml)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':mk' => $_POST['make'],
':yr' => $_POST['year'],
':ml' => $_POST['mileage']
));
$_SESSION["record"] = "Record inserted";
header("Location: view.php");
return;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mohammed Misran's Automobile Tracker</title>
</head>
<body>
<h1>Tracking Autos for <?php echo htmlentities($_SESSION['email']);?></h1>
<?php
if (isset($_SESSION['failure'])) {
echo '<p style="color: red;">'.htmlentities($_SESSION['failure'])."</p\n";
unset($_SESSION['failure']);
}
?>
<form method="post">
<p>Make:
<input type="text" name="make" size="40"/></p>
<p>Year:
<input type="text" name="year" size="40"/></p>
<p>Mileage:
<input type="text" name="mileage" size="40"/></p>
<p><input type="submit" value="Add"/>
<input type="submit" name="cancel" value="Cancel"/></p>
</form>
</body>
</html>
Good Afternoon,
I think its better to use HTML form properties, you want to validate the entered values, so its easy to do it like this:
1- 'Make' should not be empty:
<input type="text" name="make" size="40" required/>
2- 'Year' and 'Mileage' must be numeric:
<input type="number" name="year" size="40"/>
<input type="number" name="mileage" size="40"/>
by this way you dont need to write any php validation for your form, if you want to use php validation let me know to guide you for solving your problem
when Submit button press then first you have to Check Submit Button Post like this:
if(isset($_POST['submit'])){
//Your Code Logic...
}
then get data from POST & store it in variable like this... for Your Reference
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
}
in html...
<body>
<form method="post" action="">
<input type="text" name="username" placeholder="enter username"><br/><br/>
<input type="text" name="password" placeholder="enter password"><br/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
then store in database like this
$sql="insert into user(username, password)
values('$username','$password')";
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
im trying to make a basic login script that requires the correct input to be used in order to login. I also want my script to bring up an error if the wrong details are input.
I have looked around but i can't seem to find a fix for this as i don't want to use MySQL.
I want to stick to html/PHP also.
I have the basic display of the login script:
<p><b>Please Login</b></p>
<form action="useraccess.php" method="post">
Username: <input type="text" name="username"/></br>
Password: <input type="password" name="pass"/></br>
<input type="submit" value="login"/>
</form>
If anyone could help me out here that would be greatly appreciated!
cheers.
This is simple. Something like that:
<p><b>Please Login</b></p>
<form action="useraccess.php" method="post">
Username: <input type="text" name="username"/></br>
Password: <input type="password" name="password"/></br>
<input type="submit" name="submit"/>
</form>
<?php
session_start();
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
$_SESSION['loginsuccess'] = true;
header('location:accesssite.php');
die();
}
}
useraccess.php
session_start();
$username = 'admin';
$password = 'pass';
$error = '';
if($_POST['username'] != $username) $error .= 'Wrong username!<br>';
if($_POST['pass'] != $password) $error .= 'Wrong username!<br>';
if(!empty($error) {
$_SESSION['error'] = $error;
header('Location:form.php'); //your login script
}
...
continue as logged user
then in form.php (your login script)
<?php
session_start();
if(!empty($_SESSION['error'])) echo $_SESSION['error']; ?>
....
....
Your login script
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm tried to put ajax form in while element, but not work.
Probably can not be repeated id in ajax form.
<?php while(..){ ?>
<form id="cancel-server" action="process.php" method="POST">
<input type="hidden" name="task" value="cancel-server" />
<input type="hidden" name="serverid" value="<?php echo $row['sid']; ?>" />
<button type="submit" id="ah">
<i class="icon-remove"></i> Otkaži narudžbinu
</button>
</form>
<?php } ?>
jquery:
$('#cancel-server').ajaxForm({
success: function(result){
var result=trim(result);
if(result=='success'){
$.poruka('', 'Success!');
}else{
$.poruka('', result);
}
}
});
php:
case 'cancel-server':
$serverid = $_POST['serverid'];
query_basic("DELETE FROM `serveri_naruceni` WHERE `id` = '".$serverid."'");
echo 'success';
break;
try to use the following snippt of code :
<script>
function _Submit(form){
$('#cancel-server'+form.id).ajaxForm({ }););
return false;
}
</script>
<form id="cancel-server<?php echo $row['id']; ?>" action="process.php" method="POST" onsubmit="javascript: return _Submit(this);">
...
</form>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
If the login code is validated, I should go into the member page otherwise I should say on the same page..I am not sure how to write a navigation link to another page..I have seen couple of answers using headers but I didn't get it.
login.php
if($username==$dbusername&&$password==$dbpassword)
{
// If this condition is true I should go into member page
}
else
{
echo "incorrect password!"; //should stay in the same page
}
form action= "member.php" method="post"
Username: input type="text" name="username"<br/>
Password: input type="password" name="password"<br/>
input type="submit" value="LogIn"><br/><br/>
Simply use header like this:
if($username==$dbusername&&$password==$dbpassword)
{
header("location:member.php");
}
If you want a delay in the redirect you can use this:
header("Refresh: 5;url=klanten.php");
(this will wait 5 seconds before redirecting)
What you want to do can be achieved by posting to the same page, login.php
Before any html, check:
if (isset($_POST['username'])) {
if($username==$dbusername && $password==$dbpassword) {
header("location: member.php");
}
}
header("location: member.php") simply redirects to member.php if condition true.
So the form would look something like this:
form action="login.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="password" name="password" />
<input type="submit" value="LogIn" />
</form>