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 (☒)<br/> " . $conn->connect_error);}echo "sql (☑) <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)时未保存输入的值所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)