我尝试编写的代码有点问题:
代码的目的是检查表中一行的两个字段是否匹配(这两个字段已经在代码中预定义,因此 field1 和 field2)。如果它们匹配,它将在 HTML 表中显示该行中的其余信息。如果这两个字段不匹配,则它会回显一条消息。
以下是我到目前为止所得到的:
### Connects to db
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'dbname';
mysql_select_db($dbname);
echo ("<table width=\"580px\" class=\"board\" border=\>
<form method=\"post\" action=\"check_data.php\">
<tr>
<td>Field1</td>
<td>
<input type=\"text\" name=\"f1\"
size=\"20\">
</td>
</tr>
<tr>
<td>Field 2</td>
<td>
<input type=\"text\" name=\"f2\" size=\"40\">
</td>
</tr>
<tr>
<td align=\"right\">
<input type=\"submit\"
name=\"submit value\" value=\"Check\">
</td>
</tr>
</form>
</table>")
Check_data.php 包含:
### Connects to db
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'dbname';
mysql_select_db($dbname);
$id = $_POST['f1'];
$points = $_POST['f2'];
## Query
$check = "SELECT * FROM table WHERE `field1` = '$f1' AND `field2` = '$f2'";;
mysql_query($check);
echo("<div class=\"successful\">Field 1 and Field 2 match.
$check</div>");
任何帮助将不胜感激。