Hi, I'm new here and I should say, I am a raw amateur at PHP and MySQL. All I can do is look at how others do similar things and try and adapt it.
I have a MySQL table: Neil_Details. It has 4 columns: id, number, name, password.
I can enter number and name from a csv file automatically, no problem. id is the Primary Key and will auto_increment.
The column 'number' is the student numbers, name is their Chinese names.
I want to take the column number and generate a password from each number in the column password. That's all!
People tell me, "Don't use their student numbers," but once I know how to do this in principle, I can splice part of the number and Chinese name together somehow and make a more secure password.
I just want to learn how to do this in principle. Then I can do it for each class.
So far I have this, which doesn't seem to work, although I get no errors in /var/log/apache2/error.log
Could you please help me along a bit with some tips, pointers, links?
My index.php first calls '/makePassword/form.html.php'
This is called makePassword.php.
Thanks for any tips!
<?php
//start PHP session
session_start();
//check if login form is submitted
if(isset($_POST['gettable'])){
//assign variables to post values
$tablename = $_POST['tablename'];
// login to the database dbname=allstudentsdb
include $_SERVER['DOCUMENT_ROOT'] . '/includes/studentdb.inc.php';
$stmt = $pdo->prepare('SELECT * FROM ' . $tablename . ' WHERE number = :number');
$stmt->execute(['number' => $number]);
$password = password_hash($number, PASSWORD_DEFAULT);
echo 'password is ' . $password;
$stmt = $pdo->prepare('INSERT INTO ' . $tablename . ' (password) VALUES (:password)');
try{
$stmt->execute(['password' => $password]);
}
catch(PDOException $e){
$_SESSION['error'] = $e->getMessage();
}
}
echo 'Passwords made!';
// the input form to get the mysql table name
header('location: ' . '/makePassword/form.html.php');
?>