SRY我的业余问题。我写了这个代码获取文本从输入和添加到数据库:如何添加行动提交按钮
<html xmlns="http://www.w3.org/1999/xhtml" lang="fa">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Title</title>
</head>
<body>
<form action="" method="POST">
<label for="name" id="app_name_label" >name</label>
<input type="text" name="name" id="name_textfield">
<input type="submit" name"Submit" value="send" >
</form>
<?php
if(isset($_POST['Submit']))
{
include_once("config.php");
$con = mysql_connect($db_host,$db_user,$db_pass)
or die(mysql_error());
$selected=mysql_select_db($db_name, $con)
or die(mysql_error());
if($selected){
$name = $_REQUEST['name'];
$ins = "INSERT INTO infos (app_name) VALUES ('$name')";
$saved=mysql_query($ins);
if($saved)
{
echo "Saved!!";
}
else
{
echo "Don't Saved!!";
}
}
mysql_close($con);
}
?>
</body>
</html>
我的数据库没有任何问题 但是当我运行它,没有写我的数据库! :(我应该怎么办? 我认为问题出在isset($_POST['Submit'])
。
代码应该是两个不同的脚本,首先html部分被请求并由浏览器显示。然后脚本以“action”属性的形式记下来,并在那里发送表单内容。该文件(一个php文件)处理表单数据。 – arkascha
代码不必位于两个单独的文件中。 –