首先抱歉我的英语不好 第二:问题是我的形式,当sumbit他没有在同一页面或另一页面上发布插入的数据。 当我填写字段时,我需要它在同一页面或其他页面上发布 并且需要有可能在不同页面上显示已发布的内容,而无法让其他人填充字段,但只能查看/读取。
<?php
mysql_connect("sql.domain.com", "database", "password");
mysql_select_db("database");
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$eMail = $_POST['eMail'];
$eMailPw = $_POST['eMailPw'];
$submit = $_POST['submit'];
$dbLink = mysql_connect("sql.domain.com", "database", "password");
mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
if($submit) {
if($Username && $Password && $eMail && $eMailPw) {
$insert = mysql_query("INSERT INTO commenttable (Username,Password,eMail,eMailPw) VALUES ('$Username','$Password','$eMail','$eMailPw') ");
echo "<meta HTTP-EQUIV='REFRESH' content='0; url=TEST2.php'>";
} else {
echo "please fill out all fields";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST 2</title>
</head>
<body>
<center>
<form action="TEST2.php" method="POST" >
<table border="0" cellspacing="8" cellpadding="0" >
<tr>
<td>Username</td>
<td><input type="text" name="Username" size="30" ></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="Password" ></td>
</tr>
<tr>
<td>eMail</td>
<td><input type="text" name="eMail" ></td>
</tr>
<tr>
<td>eMail Password</td>
<td><input type="text" name="eMailPw" ></td>
</tr>
</table>
<input type="submit" value="Submit">
</form>
<?php
$dbLink = mysql_connect("sql.domain.com", "database", "password");
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
$getquery = mysql_query("SELECT * FROM commenttable ORDER BY id DESC");
while($rows = mysql_fetch_assoc($getquery)) {
$id = $rows['id'];
$Username = $rows['Username'];
$Password = $rows['Password'];
$eMail = $rows['eMail'];
$eMailPw = $rows['eMailPw'];
echo $Username . '<br/>' . '<br/>' . $Password . '<br/>' . '<br/>' . $eMail . '<br/>' . '<br/>' . $eMailPw . '<br/>' . '<br/>' . '<hr size="1"/>';
}
?>
</body>
</html>
答案 0 :(得分:-2)
首先,你的英语很好。其次,如果它发布与否,我会建议你做很多事情。
mysql extension depreciation warning
mysql扩展已被折旧,因此您需要使用mysqli。使用PHP的好处是文档非常全面。 Check out this link to get familiar with the improved extensions.
mysql_connect
更改为
mysqli_connect
...为用户提供了一种方式 安全地输入密码。元素呈现为一行 纯文本编辑器控件,其中文本被遮挡以便它 无法读取,通常用符号替换每个字符 作为星号(&#34; *&#34;)或点(&#34;•&#34;)。这个角色会有所不同 取决于用户代理和操作系统。 - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password
Here's a handy link to get familiar with different input types
isset - 确定变量是否已设置且不为NULL - http://php.net/manual/en/function.isset.php
if($submit){
更改为
if(isset($_POST['submit'])){
<your code here>
}
您似乎可能希望将用户重定向到其他页面,以便在提交后查看数据。以下是如何执行此操作的示例。
# after your query and insertion into table
$profile_url = 'http://' . $_SERVER['HTTP_HOST'] . '/profile.php';
$header('Location: ' . $profile_url);