Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Dear all my brothers and sisters. I am integrating HTML & PHP with MySql.
And what I need help is. How to authenticate users before changing password using their email address?
The following is what I tried:
This is my: the Change Passowrd.html form
<html>
<head>
<title></title>
</head>
<body>
<h2>Change Your Password</h2>
<form name="passwd" action="passwd.php" method="POST">
E-Mil:<input type="text" name="email" ><br>
Old Password:<input type="text" name="old_password" ><br>
New Password:<input type="text" name="new_password" ><br>
Confirm Password:<input type="text" name="confirm_password" >
<input type="submit" value="Update" width="5">
</form>
</body>
</html>
This is my: changpassword.php script file
*Example: I want to change the password 'nuru' to 'selam' whose usermail is: nur_selam#yahoo.com and match previous password.*
<html>
<head>
<title>ChangePassowrd</title>
</head>
<body>
<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$tablename="users";
//connect the server & select database
mysql_connect($dbhost, $dbuser, $dbpass)or die("cannor connect");
mysql_select_db('fb')or die("cannort select DB");
//Get values from FORM
$mail=$_POST['email'];
$oldpswd=$_POST['old_password'];
$newpswd=$_POST['new_password'];
$conpswd=$_POST['confirm_password'];
mysql_close($conn);
?>
</body>
</html>
you can try this code
Password Updater
<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$tablename="users";
//connect the server & select database
mysql_connect($dbhost, $dbuser, $dbpass)or die("cannor connect");
mysql_select_db('fb')or die("cannort select DB");
//Get values from FORM
$mail=$_POST['email'];
$oldpswd=$_POST['old_password'];
$newpswd=$_POST['new_password'];
$conpswd=$_POST['confirm_password'];
$query = mysql_query("select * from users where email = '$mail'");
while($row = mysql_fetch_array($query))
{
if($row['pass'] == $oldpswd)
{
mysql_query("update users set pass = '$newpswd' where email = '$mail'");
}
else
{
echo "Wrong password.";
exit();
}
}
mysql_close($conn);
?>
</body>
</html>
Related
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 7 months ago.
Improve this question
i download 2 php file, one is index. php for input form, and other is insert.php. i have put them on the same folder.
when i click submit it execute insert.php file it work fine and it insert form data into my database. but the question is: how it is called? no code line on the index.php calling the insert.php file.
here is a code of index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>GFG- Store Data</title>
</head>
<body>
<center>
<h1>Storing Form data in Database</h1>
<form action="insert.php" method="post">
<p>
<label for="firstName">Name:</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="lastName">Branch:</label>
<input type="text" name="branch" id="branch">
</p>
<p>
<label for="Gender">Roll Number:</label>
<input type="text" name="roll_no" id="roll_no">
</p>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
here is the code of insert.php
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>
<body>
<center>
<?php
$conn = mysqli_connect("localhost", "root", "", "test");
// Check connection
if($conn === false){
die("ERROR: Could not connect. "
. mysqli_connect_error());
}
// Taking all 3 values from the form data(input)
$name = $_REQUEST['name'];
$branch = $_REQUEST['branch'];
$roll_no = $_REQUEST['roll_no'];
// Performing insert query execution
// here our table name is college
$sql = "INSERT INTO student VALUES ('$name','$branch','$roll_no')";
if(mysqli_query($conn, $sql)){
echo "<h3>data stored in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";
}
else{
echo "ERROR: Hush! Sorry $sql. "
. mysqli_error($conn);
}
// Close connection
mysqli_close($conn);
?>
</center>
</body>
</html>
insert.php is calling after clicking on submit button by "action" attribute which you have used in tag.
<form action="insert.php" method="post">
You can set another path as well as if you want to keep insert.php on any other folder location.
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 4 years ago.
Improve this question
this is my html code
<?php include('process.php') ?>
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<from action="index.php.php" method="post">
<?php include('errors.php'); ?>
<lable> name </lable>
<input type="text" name="name" placeholder="enter your name">
<lable>location</lable>
<input type="text" name="location" placeholder="enter your location">
<button type="submit" name="save_btn" >update</button>
</from>
</body>
</html>
this is my php code
<?php
session_start();
// initializing variables
$name="";
$location="";
// connect to the database
$db = mysqli_connect('localhost', 'newuser', 'password', 'curd');
// REGISTER USER
if (isset($_POST['save_btn'])) {
// receive all input values from the form
$name = mysqli_real_escape_string($db, $_POST['name']);
$location = mysqli_real_escape_string($db, $_POST['location']);
$query = "INSERT INTO data (name, location) VALUES('$name', '$location')";
mysqli_query($db, $query);
}
why its not store in data base? data base name correct and i have 3 tables
id (ai)
name (var 200)
location (var 200)
in my browser i can locate index.php but when i click button nothing happen any one can explain why its not working?
Fine, it seems that the problem is caused by 2 important typos:
<from action="index.php.php" method="post"> should be <form action="index.php" method="post">.
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 6 years ago.
Improve this question
I'm very new to this, I made a php to test the connection with the database and it seems fine, but writing information to a table isn't working.
Heres the index.php (where the signup form is)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form action="signup.php" method="POST">
<input type="text" name="firstname" placeholder="Firstname"><br>
<input type="text" name="lastname" placeholder="Lastname"><br>
<input type="text" name="uid" placeholder="Username"><br>
<input type="text" name="pwd" placeholder="Password"><br>
<input type="submit">
</form>
</body>
</html>
Heres the signup.php (which is what i think might be broken)
<?php
include 'dbh.php';
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
$sql = "INSERT INTO useraccounts (firstname, lastname, uid, pwd)
VALUES ('$firstname', '$lastname', '$uid', '$pwd')";
$result = mysqli_query($conn, $sql);
header("Location: index.php");
?>
and heres the dbh.php which connects to mysql
<?php
$conn = mysql_connect("hostname", "username", "password", "databasename");
if (!$conn) {
die("Connection failed: ".mysql_connect_error());
}
?>
I'm sure there's already a load of questions like mine out there but I'm so new to this I'm finding it hard to learn from the answers I've come across
In your signup.php you use the following line (mysqli):
mysqli_query($conn, $sql);
However in your dbh.php you use (mysql):
mysql_connect("hostname", "username", "password", "databasename");
And
mysql_connect_error());
Other than that I can't see anything else what could be wrong.
Your query seems correct and you declare your post data.
I suggest you try to look for error messages if the solution above doesnt provide anything.
Try quote you columns with => `
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 8 years ago.
Improve this question
After hitting 'log-in' in a simple login.php, it outputs an 'Object Not Found' and having the link 'localhost/post?username=asd&password=asd&Submit=Log+In'. Can anyone help me find out what's wrong?
Here's the coding to the initial page login.php
<!DOCTYPE html>
<html>
<?php $error=""; //sets the error var to empty?>
<head></head>
<body>
<form name="form1" method="check_login.php" action="post">
Username <input name="username" type="text" id = "username" placeholder="Username">
<br><br>
Password <input name="password" type="password" id = "password" placeholder="********">
<br><br>
<input name="Submit" type="submit" value="Log In">
<br><br>
</form>
</body>
</html>
Here's check_login.php
<?php
//sets the host/username/password/database name into variables
$host = "localhost";
$user = "root";
$pass = "enterpasshere";
$myDB = "abc";
$error = "";
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
$username = $_POST['username']; //gets the username input
$password = $_POST['password']; //gets the password input
$connection = mysql_connect($host, $user, $pass); //connects to the database
mysql_select_db($myDB); //selects the database
$result = mysql_num_rows(mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password'")); //performs the query and gets the number of rows
if($result == 1){ //if the query was right
header("location: home.php");//Redirecting to other page
} else {
$error = "Wrong username or password";
}
mysql_close(); //Make sure to close out the database connection
}
?>
I used to have the form's action as ?php ($_SERVER["PHP_SELF"]);? and the code in the check_login.php inside login.php but I had the problem with error printing so I thought I'll just do this.
Your action and method are backwards. method is post or get, action is the path to the controller
<form name="form1" method="check_login.php" action="post">
Should be:
<form name="form1" action="check_login.php" method="post">
You get localhost/post?username=asd&password=asd&Submit=Log+In because the form submits to post, and assumes a get because the method is invalid, and therefore appends the form values to the query string of the URL.
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 9 years ago.
Improve this question
I have a log in page that I want to pass a value to from another page... but it wont pass can anyone help me? please.
login page code:
<!DOCTYPE html>
<?php
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" name="login" id="send" />
</form>
</body>
</html>
<?php
// Inialize session
if(isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
$repcode=$_POST['repcode'];
// Include database connection settings
include('connection.php');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE username = '$username' and password = '$password'");
// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
$_SESSION['repcode'] = $_POST['repcode'];
// Jump to secured page
$stat = "UPDATE users SET status='login'";
mysql_query($stat);
header('Location: home2.php');
}else {
}
}
?>
page to be passed:
<!DOCTYPE html>
<?php
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form method="get">
<input type="text" name="username" value="<?php echo $_POST['username']; ?> "/>
<input type="text" name="repcode" value="<?php echo $_POST['repcode']; ?> "/>
</form>
</body>
</html>
I want to pass the username and repcode to another page and put it in textboxes. Can anyone help me with this...I'm new in php and still learning.
I don't understand the goal of your code, but you need to use $_SESSION instead of $_POST in the 2nd page if you want to use the values stored in SESSION:
<form method="get" >
<input type="text" name="username" value="<?php echo $_SESSION['username']; ?> "/>
<input type="text" name="repcode" value="<?php echo $_SESSION['repcode']; ?> "/>
</form>