13684

HTML Form seemingly not posting to PHP

Question:

Hello and thank you for your time.

Regardless of the amount of research I do, I cannot find an already-discussed solution to this problem.

The problem is that the submit button automatically redirects, seemingly without posting the form. It worked until I converted from MySQL functions to MySQLi. Everything else is working but this part of the website.

<strong>HTML form (myaccount.inc.php):</strong>

<div id="change-password"> <form class="clearfix" action="" method="post"> <div><span class="he1">Change Password</span></div> <div> <?php include_once 'controllers/accountController.php'; ?> </div> <div><label class="fieldlabel" for="password">Current Password:</label></div> <input type="password" name="password" id="password" size="23" /><br /> <div><label class="fieldlabel" for="passwordnew1">New Password:</label></div> <input type="password" name="passwordnew1" id="passwordnew1" size="23" /><br /> <div><label class="fieldlabel" for="passwordnew2">Confirm New Password:</label></div> <input type="password" name="passwordnew2" id="passwordnew2" size="23" /><br /> <input type="submit" name="submit" value="Change Password" class="bt_changepass" /> </form> </div>

This form is then, for lack of a better term, controlled by some PHP.

<strong>PHP (accountController.php):</strong>

// Checking whether the Password Change form has been submitted. if(isset($_POST['submit'])=='Change Password') { echo "<br />"; // Get the data from the database. $sql = $mysqli->query("SELECT * FROM ss_members WHERE usr = '".$_SESSION['usr']."' AND pass = '".md5($_POST['password'])."'"); $row = $sql->fetch_assoc(); // Will hold our errors $err = array(); if($_POST['password'] == "" || $_POST['passwordnew1'] == "" || $_POST['passwordnew2'] == "") { $err[] = 'All the fields must be filled in!'; } if(!$row['pass'] == md5($_POST['password']) && $_POST['passwordnew1'] != "" && $_POST['passwordnew2'] != "") { $err[] = 'Current password is not correct!'; } if($_POST['passwordnew1'] <> $_POST['passwordnew2']) { $err[] = 'New passwords do not match!'; } if(!count($err)) { if($row['usr']) { // If everything is OK change password. $stmt = $mysqli->prepare("UPDATE ss_members SET pass = md5(?) WHERE usr = {$_SESSION['usr']}"); $stmt->bind_param('s', $_POST['passwordnew1']); $stmt->execute(); $stmt->close(); echo "Password has been sucessfully updated!<br />"; } else { $err[]='Something broke!'; } } if($err) { // Save the error messages in the session. foreach($err as $error) { echo $error . "<br />"; } } echo "<br />"; }

Answer1:

The problem is you are including the

<?php include_once 'controllers/accountController.php'; ?>

after the headers have been sent.

You can either move the

<?php include_once 'controllers/accountController.php'; ?>

to the top of the page, inside the handler part, or you can submit the form to

controllers/accountController.php

using

<form class="clearfix" action="controllers/accountController.php" method="post">

Answer2:

There is no action set in your <form> tag and it is sending the data to the same file. i.e., myaccount.inc.php.

Change it to:

<form class="clearfix" action="accountController.php" method="post">

Answer3:

Try this :

Give form action to accountController.php

<form class="clearfix" action="accountController.php" method="post">

Answer4:

change your action to this,because accountController.php is present inside controllers folder.

<form class="clearfix" action="controllers/accountController.php" method="post">

Answer5:

mysqli is a class, and the it's function query is not static so there, you must declare an instance of the mysqli class before you can use $mysqli->query.

You should put

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

before

$sql = $mysqli->query("SELECT * FROM ss_members WHERE usr = '".$_SESSION['usr']."' AND pass = '".md5($_POST['password'])."'");

Recommend

  • how can I sort properly with preg_match?
  • Angular route resolve calling a service
  • Custom Membership provider & MVC 4
  • Update Membership property. Method not supported
  • How to display a tooltip with the value of a slider field in a Classic UI AEM dialog?
  • ASP.NET MVC: Implementing an OpenID sign-in page ala NerdDinner v2
  • upgrading javascript that adds a link to a field
  • SQL UPDATE.. SET.. not working [duplicate]
  • ExtJS 4 - How to display template having width greater than the width of combo-box?
  • WPF Data binding: How to organize projects and classes in a solution?
  • Subtract fetched datetime from current date time
  • Assigning the contents of a file to an variable
  • make header, sidebar & footer constant across website
  • How would WP plugins need to be recoded in order to work on Modx?
  • extjs button scope
  • My PHP session won't save on hostgator
  • Retrieve User Stories and associated Test Cases with it
  • Wait for angular to finish updating the DOM
  • Unit test express route calls controller method?
  • Play 2.0.4 file upload. NullPointerException: null
  • Rails XML builder not rendering
  • Slicing an SPA into several components and use AngularJS
  • EditText is covered by Keyboard
  • event.getSource() returns null Accessibility in android
  • How to resolve permission denied maybe missing internet permission?
  • ApplePay PKPaymentAuthorizationViewController always shows processing
  • xcode don't localize specific strings
  • Authentication in Play! and RestEasy
  • Swift: Switch statement fallthrough behavior
  • MongoError: Incorrect arguments
  • Django rest serializer Breaks when data exists
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Invalid access key error using credentials redeemed from an amazon open id token
  • PHP: When would you need the self:: keyword?
  • Acquiring multiple attributes from .xml file in c#
  • Authorize attributes not working in MVC 4
  • reshape alternating columns in less time and using less memory
  • UserPrincipal.Current returns apppool on IIS
  • How can I use threading to 'tick' a timer to be accessed by other threads?