How do I insert a value into DB table when every time button action is performed

Hii am working on a project in which when a button is clicked it should generate an OTP and saves the generated value in the sql database.

My php code for OTP :

<?php

$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string_shuffled = str_shuffle($string);

$half = substr($string_shuffled, 1, 7);

echo $half ;

?>

My HTML code for button to generate OTP in login.php :

<input class="button" name="generate" id="generate" tabindex="5" value="Generate Password" type="submit">

My php action when the above button is clicked :

if(isset($_POST['generate']))
    {
           $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
           $string_shuffled = str_shuffle($string);

           $half = substr($string_shuffled, 1, 7);

           $query = "INSERT INTO `san_login`.`user_login` (`password`)   VALUES ('".$half."')";
           }

The problem is I couldn't get the output of $half to store into my table 'password' column

Answers


You did not execute your query.

You need to run this query:

$query = "INSERT INTO `san_login`.`user_login` (`password`)   VALUES ('".$half."')";

execute your query like this(e.g in mysqli_)

 mysqli_query($your_link,$query);

see details mysqli_query


Need Your Help

Handing over unicode strings to javascript with jinja2

javascript python google-app-engine unicode jinja2

I am using GAE and at some stage I decode a UTF8 string to then hand it over to an HTML file with Jinja2:

Recreate Excel RATE function using Newton's Method

php excel function financial

I'm working on converting a mortgage calculator in PHP, but I don't necessarily need a PHP solution. I'm looking for the logic needed to replicate the Excel RATE function. I've found a solution which