doujiene2845 2015-06-29 02:01
浏览 82

数据未插入数据库且没有错误

I have a problem...

Im trying to take data inserted into my html5 form and insert it into a database. Now i have the form made along with a script that should be working; instead there is no data being inserted into the database and there is no error showing. Please help.

form.php

<form name="loginForm" method="post" action="process.php">
<input id="username" type="text" placeholder="Username" name="username">
<input id="password" type="password" placeholder="Password" name="password">
<input type="submit" id="Login" class="form-control" value="Log In">
</form>

process.php

<?
$username=$_POST['username'];
$password=$_POST['password'];
mysql_connect("localhost", "root", "toor") or die(mysql_error());
mysql_select_db("formd") or die(mysql_error());  mysql_query("INSERT INTO `data` VALUES ('$username', '$password')");
Print "Your information has been successfully added to the database.";
?>

Now i know this isnt a secure way to store passwords or usernames but this isnt for any website really i just wanna know how to take information from my form and store it into a database.

  • 写回答

2条回答 默认 最新

  • drf65218 2015-06-29 02:06
    关注

    You've added minimal error handling to all mysql functions call but the one involved in the actual query....

    The script is also prone to sql injections.

    The mysql_* extension is mared as deprecated, better pick another mysql extension.

    <?php
    $mysql = mysql_connect("localhost", "root", "toor")
      or die(mysql_error());
    mysql_select_db("formd", $mysql)
      or die(mysql_error($mysql)); 
    
    $username=mysql_real_escape_string($_POST['username'], $mysql);
    $password=mysql_real_escape_string($_POST['password'], $mysql);
    
    mysql_query("INSERT INTO `data` VALUES ('$username', '$password')", $mysql)
      or die(mysql_error($mysql));
    echo "Your information has been successfully added to the database.";
    

    using or die(mysql_error()) can lead to Information Leakage issues

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口