I have this code that when submitted, it generates random number from the array.
<?php
if(isset($_POST['roll'])) {
$randarray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$randselect = array_rand($randarray);
$nr = $randarray[$randselect];
echo '<p class="btn btn-info"> Branch: '. $nr. '</p>';
}
?>
<form action="#" method="post">
<button type="submit" class="btn btn-default" name="roll">Roll Branch </button>
</form>
What I wanted to do is after the form was submitted, the button will be disabled. Any thoughts?
Just add disabled if the button is pressed, e.g.
<button type="submit" class="btn btn-default" name="roll" <?php echo isset($_POST["roll"]) ? "disabled" : "";?>>Roll Branch </button>
You can do this:
<button type="submit" class="btn btn-default" name="roll" <?php echo isset($_POST['roll']) ? 'disabled="true"' : ''; ?> >Roll Branch </button>
Add onclick="this.disabled='true';" for button tag
It is not getting enabled after page post and I got some error.
In my situation my signup page have a submit button. Below is the code :
<form action="" method="post" id="signup-form" name="signup-form">
<div class="row">
<div class="form-group col-md-12 mb-4">
<input type="text" class="form-control input-lg" id="txtFormNo" name="txtFormNo" aria-describedby="nameHelp" placeholder="Form No" required readonly>
</div>
<div class="form-group col-md-12 mb-4">
<label for="standard">Select Standard</label>
<select class="form-control" id="standard" name="standard" required>
<option>FYJC</option>
<option>SYJC</option>
</select>
</div>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtSeatNo">SSC Seat No</label>
<input type="text" class="form-control input-lg" id="txtSeatNo" name="txtSeatNo" autocomplete="off" aria-describedby="nameHelp" placeholder="SSC Seat No" maxlength="7" required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmSeatNo">Re-enter SSC Seat No</label>
<input type="text" class="form-control input-lg" id="confirmSeatNo" name="confirmSeatNo" autocomplete="off" aria-describedby="nameHelp" placeholder="Re-enter SSC Seat No" maxlength="7" required>
</div>
</div>
</div>
</div>
<?php if (isset($_GET['flag']) != 'newsyjc') { ?>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtSscAppNo">Enter Unique Application ID</label>
<input type="text" class="form-control input-lg" placeholder="UNIQUE APPLICATION ID" autocomplete="off" name="txtSscAppNo" id="txtSscAppNo" maxlength="6" required />
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmSscAppNo">Re-enter Unique Application ID</label>
<input type="text" class="form-control input-lg" placeholder="Re-enter UNIQUE APPLICATION ID" autocomplete="off" name="confirmSscAppNo" id="confirmSscAppNo" maxlength="6" required />
</div>
</div>
</div>
</div>
<?php } ?>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtContact">Enter Contact No.</label>
<input type="text" class="form-control input-lg" id="txtContact" name="txtContact" autocomplete="off" placeholder="Contact" maxlength="10" required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmContact">Re-enter Contact No.</label>
<input type="text" class="form-control input-lg" id="confirmContact" name="confirmContact" autocomplete="off" placeholder="Re-enter Contact" maxlength="10" required>
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="txtEmail">Enter Email ID</label>
<input type="email" class="form-control input-lg" id="txtEmail" name="txtEmail" aria-describedby="emailHelp" autocomplete="off" placeholder="Email ID" required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="confirmEmail">Re-enter Email ID</label>
<input type="email" class="form-control input-lg" id="confirmEmail" name="confirmEmail" aria-describedby="emailHelp" autocomplete="off" placeholder="Re-enter Email ID" required>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="d-inline-block mr-3">
<label class="control control-checkbox">
<input type="checkbox" required />
<div class="control-indicator"></div>
I Agree the terms and conditions
</label>
</div>
<button type="submit" class="btn btn-lg btn-primary btn-block mb-4" name = "btnSignup" id = "btnSignup"
<?php echo isset($_POST["btnSignup"]) ? "disabled" : "";?> >Sign Up</button>
<p>Already have an account?
<a class="text-blue" href="login.php">Sign in</a>
</p>
</div>
</div>
</form>
PHP Code :
if (isset($_POST['btnSignup'])) {
$standard = trim($_POST['standard']);
$SeatNo = trim($_POST['txtSeatNo']);
$cSeatNo = trim($_POST['confirmSeatNo']);
$FormNo = trim($_POST['txtFormNo']);
$contact = trim($_POST['txtContact']);
$cContact = trim($_POST['confirmContact']);
$Email = trim($_POST['txtEmail']);
$cEmail = trim($_POST['confirmEmail']);
$code = md5(uniqid(rand()));
$stmt = $user->runQuery("SELECT * FROM stud_personal_details WHERE SeatNo=:SeatNo");
$stmt->execute(array(":SeatNo"=>$SeatNo));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($flag == 'newsyjc') {
$SscAppNo = '';
$cSscAppNo = '';
if ($stmt->rowCount() > 0) {
$msg = "<div class='alert alert-error'>
<strong>Sorry !</strong> Seat No is Already Registered.<br>
Please enter your correct Seat No OR <a class='btn btn-success btn-lg' href='login.php'>Click here to login !</a>
</div>";
} else if ($standard == 'SYJC') {
if ($user->stud_personal_details($SeatNo, $FormNo, $SscAppNo, $Password, $contact, $code, $Email) &&
$user->stud_admission_details($SeatNo, $SscAppNo) &&
$user->stu_app($SeatNo, $code) &&
$user->Marks($SeatNo) ) {
$user->send_sms($SeatNo, $Password, $Email);
$msg = "<div class='alert alert-success' role='alert'>
<strong>Success!</strong> Your account is created.<br>
Password have been SMS on ".$contact." and mailed at ".$Email."<br>
<p><a class='text-blue' href='login.php'>Click here to login !</a></p>
</div>";
//header("refresh:3;login.php?flag=".$flag);
} else {
$msg = "<div class='alert alert-danger' role='alert'>
<strong>Sorry !</strong> Something went wrong.<br>
Contact college office or IT Charge of College.
</div>";
}
}
} else if ($days > 0) {
$SscAppNo = trim($_POST['txtSscAppNo']);
$cSscAppNo = trim($_POST['confirmSscAppNo']);
if (strlen($SeatNo) != 7 ) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> SSC Seat Number is a 7 alpha-numberic combination.<br>
Please enter again.
</div>";
} else if ($cSeatNo !== $SeatNo) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> SSC Seat Number doesn't match.<br>
Please enter again.
</div>";
} else if (strlen($SscAppNo) != 6 ) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> UNIQUE APPLICATION ID should be 6 numberic value.<br>
Please enter again.
</div>";
} else if ($cSscAppNo !== $SscAppNo) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> UNIQUE APPLICATION ID doesn't match.<br>
Please enter again.
</div>";
} else if (strlen($contact) != 10 ) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> Contact No. should be of 10 digits.
</div>";
} else if ($contact!==$cContact) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> Contact No. Doesn't match.
</div>";
} else if ($cEmail!==$Email) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry!</strong> Email Doesn't match.<br>
Please enter again.
</div>";
} else if ($stmt->rowCount() > 0) {
$msg = "<div class='alert alert-danger' role='alert'>
<i class='mdi mdi-alert mr-1'></i> <strong>Sorry !</strong> Seat No is Already Registered.<br>
Please enter your correct Seat No OR <a class='btn btn-success btn-lg' href='login.php?days=".$days."'>Click here to login !</a>
</div>";
} else if ($standard == 'FYJC') {
if ($user->stud_personal_details($SeatNo, $FormNo, $SscAppNo, $Password, $contact, $code, $Email) &&
$user->stud_admission_details($SeatNo, $SscAppNo) &&
$user->stu_app($SeatNo, $code) &&
$user->Marks($SeatNo) ) {
$user->send_sms($SeatNo, $Password, $Email, $contact);
$msg = "<div class='alert alert-success' role='alert'>
<strong>Success!</strong> Your account is created.<br>
Password have been send on ".$contact." and also mailed at ".$Email."<br>
<a class='btn btn-success btn-lg' href='login.php?days=".$days."'>Click here to login !</a>
</div>";
} else {
$msg = "<div class='alert alert-danger' role='alert'>
<strong>Sorry !</strong> Something went wrong...<br>
Contact college office or IT Charge of College.
</div>";
}
}
}
}
It stays disabled incase of some error or otherwise even after success. I mean to say it should stay disable when clicked but should get enable as soon as some error or success occurs so that user can again fill the form and click on submit again.
Related
I'm just wondering if anyone knows how to make the errors shown on this screenshot: https://imgur.com/a/eaTVR9g go underneath their dedicated input boxes like shown on this image: https://imgur.com/a/Sb1AfUj If anyone is kind enough to do it for me I would greatly appreciate it. Thank you!
Here is my code:
<?php
$title = "Register";
include ($_SERVER['DOCUMENT_ROOT'] . '/private/header.php');
if ($AUTH) {
header ('Location: /');
die();
}
if (isset($_POST['go'])) {
$username = $_POST['username'];
$email = strtolower($_POST['email']);
$password = $_POST['password'];
$passwordConfirm = $_POST['confirmPassword'];
$protectedPassword = password_hash($password, PASSWORD_ARGON2I);
// Validation Checks
$errors = array();
$Emailstmt = $db->prepare("SELECT * FROM `Users` WHERE `Email` = :email;");
$Emailstmt->bindParam(':email', $email, PDO::PARAM_STR);
$Emailstmt->execute();
if ($Emailstmt->rowCount() > 0) {
$error[] = 'The email you tried to use is already being used on an different account, please use another one.';
}
$Userstmt = $db->prepare("SELECT * FROM `Users` WHERE `Username` = :username;");
$Userstmt->bindParam(':username', $username, PDO::PARAM_STR);
$Userstmt->execute();
$checkIP = $db->prepare("SELECT count(*) FROM `Users` WHERE `LastIP` = :regIP");
$checkIP->bindParam(":regIP", $UserIP, PDO::PARAM_STR);
$checkIP->execute();
$checkIpAdress = $checkIP->fetchColumn();
if (empty($checkIpAdress)) {
$checkIpAdress = 0;
}
if ($checkIpAdress) {
if ($checkIpAdress > 3) {
array_push($errors, 'It looks like you have registered too many accounts under this IP address.');
}
}
if (strlen($username) < 3) {
array_push($errors, 'Your username must be at least 3 characters in total.');
}
if (strlen($password) < 5) {
array_push($errors, 'Your password must be at least 5 characters in total.');
}
if ($Userstmt->rowCount() > 0) {
array_push($errors, 'The username you tried to use is already being used, Maybe try to pick another one.');
}
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
//echo("$email is a valid email address");
} else {
array_push($errors, 'The email you specified(' . htmlspecialchars($email, ENT_QUOTES, "UTF-8") . ') is invaild.');
}
if (!preg_match("/^[a-zA-Z0-9][\w\.]+[a-zA-Z0-9]$/", $username)) {
array_push($errors, 'The username you specified(' . htmlspecialchars($username, ENT_QUOTES, "UTF-8") . ') contains special symbols or is invaild.');
}
if (strtolower($username) == strtolower($password)) {
array_push($errors, 'Your password can not be the same as your username.');
}
if ($password !== $passwordConfirm) {
array_push($errors, 'It looks like your passwords do not match.');
}
// Begin form submission
if (empty($errors)) {
$insert = $db->prepare("INSERT INTO `Users` (`Username`,`Email`,`Password`,`LastIP`,`TimeRegister`,`AvatarURL`) VALUES (:Username,:Email,:Password,:LastIP,:TimeRegister,:AvatarURL)");
$insert->bindParam(":Username", $username, PDO::PARAM_STR);
$insert->bindParam(":Email", $email, PDO::PARAM_STR);
$insert->bindParam(":Password", $protectedPassword, PDO::PARAM_STR);
$insert->bindParam(":LastIP", $UserIP, PDO::PARAM_STR);
$insert->bindParam(":TimeRegister", $now, PDO::PARAM_INT);
$insert->bindValue(":AvatarURL", '8ca17bec-0320-4293-90e5-dfc5b8690156', PDO::PARAM_STR);
$insert->execute();
?>
<div class="space">
<section class="hero is-success">
<div class="hero-body modal-button" data-target="modal" aria-haspopup="true"
style="padding: 1rem 1rem !important;">
<center>You have successfully registered! Please wait while we redirect you.</center>
</div>
</section><br>
</div>
<meta http-equiv='refresh' content='5;url=/auth/login' />
<?php
} else {
}
}
if ($SiteSettings->Registration == 0) {
echo '<section class="section">
<div class="container">
<div class="columns is-centered">
<div class="column is-7">
<div class="box">
<p>We\'re sorry, but account creation is currently disabled right now. Please try again later.</p>
</div>
</div>
</div>
</section>
';
include($_SERVER['DOCUMENT_ROOT'] . "/private/footer.php");
die;
}
?>
<section class="section">
<div class="container">
<div class="columns is-centered">
<div class="column is-7">
<div class="box">
<div class="title is-size-4">Register</div>
<form action="#" method="POST">
<input type="hidden" name="token" value="<?php echo $_SESSION["csrf_token"]; ?>" />
<div class="field">
<label class="label">Username</label>
<div class="control has-icons-left">
<input class="input" name="username" type="text" id="username" maxlength="15"
autocomplete="off" placeholder="Enter a username">
<span class="icon is-small is-left"><i class="fas fa-user"></i></span>
<p id="username_message"></p>
</div>
</div>
<div class="field">
<label class="label">E-Mail address</label>
<div class="control has-icons-left">
<input class="input" name="email" type="email" id="email" maxlength="128"
autocomplete="off" placeholder="Enter your e-mail address.">
<span class="icon is-small is-left"><i class="fas fa-envelope"></i></span>
<p id="email_message"></p>
</div>
</div>
<div class="field">
<label class="label">Password</label>
<div class="control has-icons-left">
<input class="input" name="password" type="password" id="password" maxlength="45"
autocomplete="off" placeholder="Enter your password.">
<span class="icon is-small is-left"><i class="fas fa-lock"></i></span>
<p id="password_message"></p>
</div>
</div>
<div class="field">
<label class="label">Confirm Password</label>
<div class="control has-icons-left">
<input class="input" name="confirmPassword" type="password" id="confirmPassword"
maxlength="45" autocomplete="off" placeholder="Confirm your password">
<span class="icon is-small is-left"><i class="fas fa-lock"></i></span>
<p id="confirmPassword_message"></p>
</div>
</div>
<div class="push-5"></div>
<button class="button is-success is-fullwidth" type="submit" name="go"><b>Register</b></button>
</form>
<?php
if (!empty($errors)) {
?>
<?php
foreach ($errors as $error) {
echo '<p class="help has-text-danger">' . $error . '</p>';
}
} ?>
</div>
<p class="has-text-centered">Already a member? Login</p>
</div>
</div>
</div>
</section>
<?php include ($_SERVER['DOCUMENT_ROOT'] . '/private/footer.php'); ?>
You can organize the array keys to reflect the fields they relate to, IE:
if (strlen($username) < 3) {
$errors['username'][] = 'Your username must be at least 3 characters in total.';
}
and then on the display side you can use said keys to identify what errors belong to what field, IE:
<div class="field">
<label class="label">Username</label>
<div class="control has-icons-left">
<input class="input" name="username" type="text" id="username" maxlength="15" autocomplete="off" placeholder="Enter a username">
<span class="icon is-small is-left"><i class="fas fa-user"></i></span>
<p id="username_message">
<?php if (isset($errors['username'])): ?>
<?php foreach($errors['username'] as $error): ?>
<?= $error ?> <br/>
<?php endforeach; ?>
<?php endif; ?>
</p>
</div>
This is the html code for the change password page. When I click change password from the user registration table, it bring me here and it works perfectly but when you use the option of the user change password which leads you directly to this place, saving it doesn't work. I believe it's got to deal with the User ID as key since from the table is selected via ID. But when i use setting - user change password, it doesn't do anything after saving password change, it doesn't reflect anything
<div class="col-lg-6">
<div class="col-sm-12">
<br/>
<h3 class="page-title">Change Password</h3>
</div>
<div class="card-box">
<div class="form-group">
<label for="userName">User Name</label>
<input type="text" name="uname" parsley-trigger="change" required placeholder="Enter user name" class="form-control" id="uname" name="uname" value="<?php echo $actordetails->ACT_USERNAME;?>" readonly >
</div>
<div class="form-group">
<label for="pass1">New Password<span style="color:#F00">*</span></label>
<input id="pass1" type="password" placeholder="Password" name="inputpassword" required class="form-control">
</div>
<div class="form-group">
<label for="passWord2">Confirm New Password <span style="color:#F00">*</span></label>
<input data-parsley-equalto="#pass1" type="password" required placeholder="Password" class="form-control" id="password2">
</div>
<div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light" type="submit" onclick="document.getElementById('viewpage').value='savepwd';document.getElementById('view').value='';document.getElementById('fdsearch').value='';document.myform.submit()">
Save
</button>
<button class="btn btn-default waves-effect waves-light m-l-5" onclick="document.getElementById('view').value='';document.getElementById('viewpage').value='';document.myform.submit()">
Cancel
</button>
</div>
</div>
</div>
</form >
and this is the controller code to process the information. The encryption uses username and password with salt for your information.. Any help would be appreciated
<?php
$crypt = new cryptCls();
switch(strtolower($viewpage)) {
case "changepwd":
print_r($_POST);
$stmt = $sql->Execute($sql->Prepare("
SELECT ACT_USERNAME,ACT_ID
FROM gm_actors
WHERE ACT_ID=".$sql->Param('a')),array($keys));
print $sql->ErrorMsg();
if($stmt->RecordCount()>0){
$editobj = $stmt->FetchNextObject();
$uname = $actordetails->ACT_USERNAME;
}
break;
case "savepwd":
print_r($_POST);
$duplicatekeeper = $session->get("post_key");
if($action_key != $duplicatekeeper){
$session->set("post_key",$action_key);
if(!empty($inputpassword) && !empty($keys) ) {
$inputpassword = $crypt->loginPassword($uname,$inputpassword);
$stmt = $sql->Execute($sql->Prepare("
UPDATE gm_actors
SET ACT_USERPASSWORD=".$sql->Param('b')."
WHERE ACT_ID=".$sql->Param('d')." "),
array($inputpassword,$actordetails->ACT_ID));
$msg = "Password has been changed successfully.";
$status = "success";
// $activity = ' Agent'.$keys.' password changed .';
// $engine->setEventLog("032",$activity);
}else if($inputpassword!==$confirmpassword){
$msgs="Sorry! Passwords Do not Match.";
$target ='changepwd';
} else {
$msg = "Unsuccessfully: All fields are required.";
$status = "error";
$view ="changepwd";
}
}
break;
}
$stmtusers = $sql->Execute($sql->Prepare("
SELECT ACT_SURNAME,ACT_ID,ACT_OTHERNAMES,
ACT_USERNAME,ACT_STATUS,ACT_EMAIL,ACT_PHONE,
ACT_ACCESS_LEVEL,ACL_NAME
FROM gm_actors
left join gm_actors_level on ACT_ACCESS_LEVEL=ACL_NUMBER
WHERE ACT_ACCESS_LEVEL !='1'
AND ACT_STATUS !='4'
ORDER BY ACT_SURNAME "));
print $sql->ErrorMsg();
include("model/js.php");
include('public/alertmessage/message.php');
?>
Modal will not trigger my PHP validation.
I can't get my modal to use my PHP validation. HTML validation works. It connects to the DB and makes the updates, but skips the server-side validation. I would appreciate any help, this is new to me why a modal won't validate.
My PHP and Modal form is in one file. I know I need more error messages added to my form, but leaving the phone number and first name out triggers no error messages, so I will add more once I fix this issue. The code just executes and changes the DB.
<?php
//ini_set( 'display_errors', 1 );
//error_reporting( E_ALL );
session_start();
// Include db config
require_once 'includes/dbh.inc.php';
// Process form when post submit
// if($_SERVER['REQUEST_METHOD'] === 'POST'){
// Sanitize POST
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$error=array();
// $error = false;
// $error = isset($_SESSION['error']);
// $error = $_SESSION['error'];
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$first = test_input($_POST['first']);
$last = test_input($_POST['last']);
$email = test_input($_POST['email']);
$unit = $_SESSION['unit'];
$bed = test_input($_POST['bed']);
$bath = test_input($_POST['bath']);
$web = test_input($_POST['web']);
$phone = test_input($_POST['phone']);
$manage = test_input($_POST['manage']);
$ck = $_POST['rent'];
$id = $_SESSION['id'];
// Validate name
if(empty($first) || empty($last)){
$error['name'] = "Enter name";
}
// Validate email
if(empty($email)){
$error['email'] = "Please enter email";
}
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error['email'] = "Invalid email format";
}
// Validate name
if(empty($bed) || empty($bath)){
$error['rooms'] = 'Please enter bed/bath #';
}
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&##\/%?=~_|!:,.;]*[-a-z0-9+&##\/%=~_|]/i",$web)) {
$error['web'] = "Invalid URL";
}
// Validate name
if(empty($phone)){
$error['phone'] = 'Please enter your phone';
}
//Check phone # format 000-000-0000
if(!preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone)) {
$error['phone'] = 'Please enter correct phone format';
}
//Check manage format
if (!preg_match("/^(\s\(([^)]+)\))?[[:punct:]]?\p{Lu}+(?:[\s'-]?[\p{L}\d]+)+(\(([^)]+)\))*$/", $manage)) {
$error['manage'] = 'Please enter correct management format';
}
if (empty($error)) {
var_dump($error);
print_r($error);
$sql = 'UPDATE condos_hp SET user_firstname=:first, user_lastname=:last, user_email=:email, user_bed=:bed, user_bath=:bath, user_web=:web, user_phone=:phone, user_manage=:manage, rent=:rent WHERE id=:id';
// Prepare statement
$stmt = $pdo->prepare($sql);
// Bind params
$stmt->bindParam(':first', $first, PDO::PARAM_STR);
$stmt->bindParam(':last', $last, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
// $stmt->bindParam(':unit', $unit);
$stmt->bindParam(':bed', $bed, PDO::PARAM_INT);
$stmt->bindParam(':bath', $bath, PDO::PARAM_INT);
$stmt->bindParam(':web', $web, PDO::PARAM_STR);
$stmt->bindParam(':phone', $phone, PDO::PARAM_STR);
$stmt->bindParam(':manage', $manage, PDO::PARAM_STR);
$stmt->bindParam(':rent', $ck, PDO::PARAM_INT);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute(array(':first'=>$first, ':last'=>$last, ':email'=>$email, ':bed'=>$bed, ':bath'=>$bath, ':web'=>$web, ':phone'=>$phone, ':manage'=>$manage, ':rent'=>$ck, ':id'=>$id));
// if($stmt){
// header('Location: index1.php');
//}
if (isset($_POST['update'])) {
// session_start();
//Then delete all SESSION variables
session_unset();
//And destroy the current session that is running
session_destroy();
// exit(header("Location: http://www.harbour-place.com/login0.php?update=success"));
if (headers_sent()) {
die("Redirect failed. Please click on this link: <a href=http://www.harbour-place.com/login0.php>");
}
else{
exit(header("Location: http://www.harbour-place.com/login0.php?update=success"));
}
}
}
include_once 'includes/mailer2.php';
?>
<!-- Button trigger modal -->
<div class="row justify-content-center">
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#exampleModalCenter">
UPDATE
</button>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="userupdateform" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">UPDATE RENTAL UNIT # <?php echo htmlentities($_SESSION['unit']) ?> </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<div class="form-row justify-content-center">
<div class="form-group col-md-4">
<label >First Name</label>
<input type="text" class="form-control form-control-sm <?php echo (!empty($error['name'])) ? 'is-invalid' : ''; ?>" name="first" value="<?php echo htmlentities($_SESSION['first']) ?>">
<span class="invalid-feedback"><?php echo $error['name']; ?></span>
</div>
<div class="form-group col-md-4">
<label >Last Name</label>
<input type="text" class="form-control form-control-sm" name="last" value=<?php echo htmlentities($_SESSION['last']) ?> required>
</div>
</div>
<div class="form-row justify-content-center">
<div class="form-group col-md-8">
<label >Email</label>
<input type="text" class="form-control form-control-sm" name="email" value=<?php echo htmlentities($_SESSION['email']) ?> required>
</div>
<!--<div class="form-group col-md-4">
<label >Unit</label>
<input type="text" class="form-control form-control-sm" name="unit" value=<php echo $_SESSION['u_unit'] ?> required>
</div>-->
</div>
<div class="form-row justify-content-center">
<div class="form-group col-md-2">
<label >Bed</label>
<input type="text" class="form-control form-control-sm" name="bed" value=<?php echo htmlentities($_SESSION['bed']) ?> required>
</div>
<div class="form-group col-md-2">
<label >Bath</label>
<input type="text" class="form-control form-control-sm" name="bath" value=<?php echo htmlentities($_SESSION['bath']) ?> required>
</div>
<div class="form-group col-md-4">
<label >Web Site - www.myunit.com</label>
<input type="text" class="form-control form-control-sm" name="web" value=<?php echo htmlentities($_SESSION['web']) ?> required>
</div>
</div>
<div class="form-row justify-content-center">
<div class="form-group col-md-3">
<label >Phone 000-000-0000</label>
<input type="text" id="yourphone2" class="form-control form-control-sm <?php echo (!empty($error['phone'])) ? 'is-invalid' : ''; ?>" name="phone" value="<?php echo htmlentities($_SESSION['phone']) ?>">
<span class="invalid-feedback"><?php echo $error['phone']; ?></span>
</div>
<div class="form-group col-md-5">
<label >Managment Co (VRBO, Self,etc)</label>
<input type="text-capitalize" class="form-control form-control-sm" name="manage" value="<?php echo htmlentities( $_SESSION['manage']) ?>" required>
</div> </div>
<!--<div class="form-row justify-content-center">
<div class="form-group col-md-8">
<label >Managment Co - VRBO etc.</label>
<input type="text" class="form-control form-control-sm" name="manage" value="" required>
</div></div>-->
<div class="form-row justify-content-center">
<div class="custom-control custom-checkbox">
<input type="hidden" name="rent" value="0">
<input type="checkbox" value="1" name="rent" class="custom-control-input" id="customCheck1" checked="checked">
<label class="custom-control-label" for="customCheck1">Check to show on the rental site</label>
</div></div>
<p class="text-center mb-1"><small><i class="fas fa-lock"></i>Your Information is Safe With us!<br> You will need to re-login after clicking Update<br>This also updates the HP rental website listing. </small></p>
<button type="submit" class="btn btn-primary btn-sm" name="update">UPDATE HP UNIT</button>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
There are a couple issues here
You are setting $error to a boolean value, trying to define an array key with a value on a boolean doesn't work, it will continue to just be a boolean [Edit] if the value of $error evaluates to false before assigning array key => values to it, it will convert to an array but if it evaluates to true it will result in Warning: Cannot use a scalar value as an array and continue to be a boolean
You are never checking $error to stop the script from executing and updating the database
I'm trying to enter data into a mysql database using php / html form but it isn't working and I don't know why. The record is not inserted and the page just refresh
I apologize for some of it being written in Danish
I have 2 files 1 with html and php and 1 with only php
My database: Database image
This is the html form and php:
<div class="row">
<div class="col-sm-12">
<?php
if (isset($_POST['Submit'])) {
// echo "<pre>", print_r($_POST), "</pre>";
$apply_name = mysqli_real_escape_string($db, $_POST ['apply_name']);
$apply_age = mysqli_real_escape_string($db, $_POST ['apply_age']);
$apply_ingame_name = mysqli_real_escape_string($db, $_POST ['apply_ingame_name']);
$apply_email = mysqli_real_escape_string($db, $_POST ['apply_email']);
$apply_steamID = mysqli_real_escape_string($db, $_POST ['apply_steamID']);
$apply_text = mysqli_real_escape_string($db, $_POST ['apply_text']);
$errors = []; // Array
if ($apply_name == "") {
$errors['apply_name'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet noget navn!</strong>
</div>";
} elseif (strlen($apply_name) < 2) {
$errors['apply_name'] = "<div class='alert alert-info'>
<strong>Dit navn skal minimum være 2 karatere</strong>
</div>";
}
if ($apply_age == "") {
$errors['create_apply_age'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet din alder!</strong>
</div>";
}
if ($apply_ingame_name == "") {
$errors['create_apply_ingame_name'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet noget In-Game navn!</strong>
</div>";
} elseif (strlen($apply_ingame_name) < 2) {
$errors['create_apply_ingame_name'] = "<div class='alert alert-info'>
<strong>Dit In-Game navn skal minimum være 2 karatere</strong>
</div>";
}
if ($apply_email == "") {
$errors['create_apply_email'] = "<div class='alert alert-danger'>
<strong>Email skal udfyldes!</strong>
</div>";
} elseif (!filter_var($apply_email, FILTER_VALIDATE_EMAIL)) {
$errors['create_apply_email'] = "<div class='alert alert-info'>
<strong>Email er ugyldig</strong>
</div>";
}
if ($apply_steamID == "") {
$errors['create_apply_steamID'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet noget SteamID!</strong>
</div>";
} elseif (strlen($apply_steamID) < 18) {
$errors['create_apply_steamID'] = "<div class='alert alert-info'>
<strong>Dit SteamID ser sådan her ud STEAM_0:0:XXXXXXXX</strong>
</div>";
}
if ($apply_text == "") {
$errors['create_apply_text'] = "<div class='alert alert-danger'>
<strong>Du har ikke skrevet noget om dig selv!</strong>
</div>";
}
if (empty($errors)) {
// Send ansøning
$created = create_apply($apply_name, $apply_age, $apply_ingame_name, $apply_email, $apply_steamID, $apply_text);
if ($created) {
echo "
<div class='alert alert-info'>
<strong>Din ansøning er sendt.</strong>
</div>
";
} else {
// Ansøning kunne ikke sendes
$create_error = "Ansøningen kunne ikke sendes, SteamID eksistere i forvejen";
}
} else {
$create_error = "Der opstod en fejl, Prøv igen";
}
}
?>
<section>
<hr>
<form class="form-horizontal" enctype="multipart/form-data" id="signup" method="post" name="signup" action="?p=askforsignup">
<?php
if (isset($errors['apply_name'])) {
echo $errors['apply_name'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Navn <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span><input class="form-control" id="mem_name" name="apply_name" placeholder="Navn" type="text" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_age'])) {
echo $errors['create_apply_age'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Alder <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span><input class="form-control" id="age" name="apply_age" placeholder="Alder" type="date" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_ingame_name'])) {
echo $errors['create_apply_ingame_name'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">In-Game Name <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span><input class="form-control" id="ingame_game" name="apply_ingame_name" placeholder="In-Game Name" type="text" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_email'])) {
echo $errors['create_apply_email'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Email <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span><input class="form-control" id="emailid" name="apply_email" placeholder="Email" type="email" value="" >
</div><small>Your Email is being used for ensuring the security of your account, authorization and access recovery.</small>
</div>
</div>
<?php
if (isset($errors['create_apply_steamID'])) {
echo $errors['create_apply_steamID'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Steam ID <span class="text-danger">*</span></label>
<div class="col-md-5 col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-steam"></i></span><input class="form-control" id="contactnum" name="apply_steamID" placeholder="Steam ID" type="text" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_text'])) {
echo $errors['create_apply_text'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Beskriv dig selv <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-id-card"></i></span>
<textarea class="form-control" rows="5" id="message" name="apply_text" placeholder="Beskriv dig selv." ></textarea>
</div><br>
<div class="col-xs-offset-8 col-xs-10 pull-right">
<input class="btn btn-primary" name="Submit" type="submit" value="Sign Up">
</div>
</div>
</div>
</form>
</section>
</div><!--/.col-sm-8-->
</div>
And this is the php code:
function create_apply($apply_name, $apply_age, $apply_ingame_name, $apply_email, $apply_steamID, $apply_text) {
global $db;
$steamID_exists = steamID_exists($apply_steamID);
if ($steamID_exists == false) {
$apply_name = mysqli_real_escape_string($db, $apply_name);
$apply_age = mysqli_real_escape_string($db, $apply_age);
$apply_ingame_name = mysqli_real_escape_string($db, $apply_ingame_name);
$apply_email = mysqli_real_escape_string($db, $apply_email);
$apply_steamID = mysqli_real_escape_string($db, $apply_steamID);
$apply_text = mysqli_real_escape_string($db, $apply_text);
$query = "INSERT INTO member_applys
(apply_name, apply_age, apply_ingame_name, apply_email, apply_steamID, apply_text, apply_date)
VALUES
('$apply_name', '$apply_age', '$apply_ingame_name', '$apply_email', '$apply_steamID', '$apply_text', NOW())";
$result = $db->query($query);
return true;
} else {
// Brugeren eksistere opret = falsk
return false;
}
}
Solved
the problem was google autocomplete was on not off
Di you be sure that your script call well the form?
I see:
....action="?p=askforsignup">
try:
....action="your_script.php">
I have created a signup form for my php website using Bootstrap but nothing happens when I click on register. Signup form is made in Bootstrap and it is not working.
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
<?php
require_once("company-db.php");
if (!isset($_POST['submit'])) {
?>
<form role="form" action="<?=$_SERVER['PHP_SELF']?>" method="post">
<h2>Please Sign Up <small>It's free and always will be.</small></h2>
<hr class="colorgraph">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="username" id="username" class="form-control input-lg" placeholder="Username" tabindex="1">
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="2">
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="company_name" id="company_name" class="form-control input-lg" placeholder="Company Name" tabindex="3">
</div>
<div class="form-group">
<input type="text" name="description" id="description" class="form-control input-lg" placeholder="Company Description" tabindex="4">
</div>
<div class="form-group">
<input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Address" tabindex="4">
</div>
<div class="row">
<div class="col-xs-4 col-sm-3 col-md-3">
<span class="button-checkbox">
<button type="button" class="btn" data-color="info" tabindex="7">I Agree</button>
<input type="checkbox" name="t_and_c" id="t_and_c" class="hidden" value="1">
</span>
</div>
<div class="col-xs-8 col-sm-9 col-md-9">
By clicking <strong class="label label-primary">Register</strong>, you agree to the Terms and Conditions set out by this site, including our Cookie Use.
</div>
</div>
<hr class="colorgraph">
<div class="row">
<div class="col-xs-12 col-md-6"><input type="submit" value="submit" class="btn btn-primary btn-block btn-lg" tabindex="7"></div>
<div class="col-xs-12 col-md-6">Sign In</div>
</div>
</form>
<?php
} else {
## connect mysql server
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
## query database
# prepare data for insertion
$username = $_POST['username'];
$password = $_POST['password'];
$company_name = $_POST['company_name'];
$description = $_POST['description'];
$email = $_POST['email'];
# check if username and email exist else insert
$exists = 0;
$result = $mysqli->query("SELECT username from companies WHERE username = '{$username}' LIMIT 1");
if ($result->num_rows == 1) {
$exists = 1;
$result = $mysqli->query("SELECT email from companies WHERE email = '{$email}' LIMIT 1");
if ($result->num_rows == 1) $exists = 2;
} else {
$result = $mysqli->query("SELECT email from companies WHERE email = '{$email}' LIMIT 1");
if ($result->num_rows == 1) $exists = 3;
}
if ($exists == 1) echo "<p>Username already exists!</p>";
else if ($exists == 2) echo "<p>Username and Email already exists!</p>";
else if ($exists == 3) echo "<p>Email already exists!</p>";
else {
# insert data into mysql database
$sql = "INSERT INTO `companies` (`id`, `username`, `password`, `company_name`, `description`, `email`)
VALUES (NULL, '{$username}', '{$password}', '{$company_name}', '{$description}', '{$email}')";
if ($mysqli->query($sql)) {
//echo "New Record has id ".$mysqli->insert_id;
echo "<p>Registred successfully!</p>";
} else {
echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>";
exit();
}
}
}
?>
</div>
</div>
You don't have a name for your submit button, so this won't get posted.
<input type="submit" value="submit" name="submit"
class="btn btn-primary btn-block btn-lg" tabindex="7">
Give the name attribute and make it set.
Note: You must never rely on Submit button's attribute!
The (!isset($_POST['submit'])) conditional statement depends on the execution of your code.