php - 每次执行按钮操作时如何将值插入数据库表

标签 php mysql sql authentication one-time-password

Hii 正在开发一个项目,其中单击按钮时应生成 OTP 并将生成的值保存在 sql 数据库中。

我的 OTP php 代码:

<?php

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

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

echo $half ;

?>

我的用于在login.php中生成OTP的按钮的HTML代码:

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

单击上述按钮时我的 php 操作:

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."')";
           }

问题是我无法将 $half 的输出存储到我的表“密码”列中

最佳答案

您没有执行查询。

您需要运行此查询:

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

像这样执行你的查询(例如在mysqli_中)

 mysqli_query($your_link,$query);

查看详情mysqli_query

关于php - 每次执行按钮操作时如何将值插入数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22343068/

相关文章:

php - 解析错误 : syntax error, 第 1 行意外的 T_STRING

mysql - SQL 外键和引用其他表

php - Paypal 订阅 IPN 自定义变量

sql - MySQL - 新手问题 : Which are the PK and the FK for these tables?

php - Laravel - 哈希器/重置密码问题

java - 为什么即使表为空,Hibernate 的 DELETE 也会返回 1?

java - 为 Android 应用解析来自服务器的非常复杂的 JSON 响应

sql - postgis上的多表查询

php - 当 php-mysql 脚本失败时如何获得详细的错误报告?

php - Ajax 响应在服务器上是 JSON,而在本地计算机上使用 CakePHP 时是 STRING,为什么?