从html表单插入数据到sql数据库(html,php,sql)时未保存输入的值

从html表单插入数据到sql数据库(html,php,sql)时未保存输入的值,第1张

概述问题:insert.php连接正常,但是当我在html表单上点击’save’时,只插入空值(”).我正在尝试插入的文字我没有保存.在某个地方没有建立连接,数据丢失但我无法确切地知道在哪里.有帮助吗? HTML插入表单(收集2个参数的数据,’用户’和’线程’) <form action="insert.php" method="post">user: <input type="text" name 问题:insert.PHP连接正常,但是当我在HTML表单上点击’save’时,只插入空值(”).我正在尝试插入的文字我没有保存.在某个地方没有建立连接,数据丢失但我无法确切地知道在哪里.有帮助吗?

HTML插入表单(收集2个参数的数据,’用户’和’线程’)

<form action="insert.PHP" method="post">user: <input type="text" name="user"><br>thread: <input type="text" name="thread"><br><input type="submit" value="Save"></form>

PHP代码连接到sql,插入输入的值

<?PHP$user = $_POST['user'];$thread = $_POST['thread'];$servername = "##.##.###";$username = "harwoodjp";$password = "~";$dbname = "332";//create connection$conn = new MysqLi($servername,$username,$password,$dbname);//check connectionif ($conn->connect_error) {    dIE("sql (&#9746)<br/> " . $conn->connect_error);}echo "sql (&#9745) <br/>";$sql = MysqL_connect($servername,$password);MysqL_connect($servername,$password);MysqL_select_db("332project");//insert values$insert_query = "INSERT INTO test1(user,thread) VALUES ('$user','$thread')";MysqL_query($insert_query);echo "<script>window.location='select.PHP'</script>"; //select.PHP displays the full table//close MysqLMysqL_close($sql);?>
解决方法 试试这个

<?PHP$user = $_POST['user'];$thread = $_POST['thread'];$servername = "localhost";$username = "root";$password = "";$dbname = "db";//create connection$conn = MysqL($servername,$password);MysqL_select_db("db");//insert values$insert_query = "INSERT INTO test1(user,'$thread')";MysqL_query($insert_query);echo "<script>window.location='select.PHP'</script>"; //select.PHP displays the full table//close MysqLMysqL_close($sql);?>
总结

以上是内存溢出为你收集整理的从html表单插入数据到sql数据库(html,php,sql)时未保存输入的值全部内容,希望文章能够帮你解决从html表单插入数据到sql数据库(html,php,sql)时未保存输入的值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1055570.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存