所以我正在为一个类创建一个基本的mysql连接到php提交表单,并在尝试将信息发布到字段时遇到错误。
在尝试提交信息之前,一切似乎都很好,它最终只是将我带回到html文件所在的同一页面,而不会将我带到链中的下一个进程,它应该在一个简单的地方显示我的条目行/列格式。
我的html代码如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> <!-- Start of FORM -->
<!-- End of FORM -->
</head>
<body>
<center><h1 id="top">Add a Source & Argument</h1></center>
<form method="post" action="add_argument.php">
<label for="claimant" >Who made the claim?:</label><input type="text" id="claimaint" name="claimant" value=""><br />
<label for="where">Where was the claim made?: </label><input type="text" name="where" id="where" value=""><br />
<label for="claim">What is the claim?:</label><input type="text" name="claim" id="claim" value=""><br />
<label for="counterpoint">What is the counterpoint?:</label><input type="text" name="counterpoint" id="counterpoint" value=""><br />
<label for="citation">Cite the source:</label><input type="text" name="citation" id="citation" value=""><br />
<input type="hidden" name="done" value="no">
<input type="submit" name="submit" value="save to the list">
</form>
</body>
</html>
<?
//check for required fields
if ((!$_POST[to])) {
header("Location: add_argument.html");
exit;
}
//set up database and table names
$db_name ="mattDB";
$table_name ="counter_point";
//connect to MySQL and select database to use
$connection = @mysql_connect("localhost","matt","Nunquam") or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());
//create SQL statement and issue query
//$sql = "INSERT INTO $table_name (id, claimant, where, claim, counterpoint, citation, done) VALUES ('', '$_POST[claimaint]', '$_POST[where]', '$_POST[claim]','$_POST[counterpoint]','$_POST[citation]', '$_POST[done]')";
$sql = "INSERT INTO $table_name VALUES ('', '$_POST[claimant]', '$_POST[where]', '$_POST[claim]','$_POST[counterpoint]','$_POST[citation]', '$_POST[done]')";
$result = @mysql_query($sql,$connection)or die(mysql_error());
?>
<HTML>
<HEAD>
<TITLE>Add an argument</TITLE>
</HEAD>
<BODY>
<center><h1 id="top">My Data Entry Log</h1></center></br>
<H1 align="center">Adding an argument to <? echo "$table_name"; ?></H1>
<div align="center">
<TABLE CELLSPACING=3 CELLPADDING=3>
<TR>
<TD VALIGN=TOP>
<P><STRONG>Claimant</STRONG><BR>
<? echo "$_POST[claimant]"; ?></P>
</TD>
<TD VALIGN=TOP>
<P><STRONG>Where</STRONG><BR>
<? echo "$_POST[where]"; ?>
</P>
</TD>
</TR>
<TR>
<TD VALIGN=TOP>
<P><STRONG>Claim</STRONG><BR>
<? echo "$_POST[claim]"; ?></P>
</TD>
<TD VALIGN=TOP>
<P><STRONG>Counterpoint</STRONG><BR>
<? echo "$_POST[counterpoint]"; ?></P>
</TD>
</TR>
<TR>
<TD VALIGN=TOP>
<P><STRONG></STRONG>Citation<BR>
<? echo "$_POST[citation]"; ?></P>
</TD>
<TD VALIGN=TOP>
<P><STRONG></STRONG>Verified<BR>
<? echo "$_POST[done]"; ?></P>
</TD>
</TR>
<tr><td>
<P><a href="add_argument.html">Add New Entry</a></P>
<P><a href="show_arguments.php">Show The Whole List</a></P>
</TD>
</TR>
</TABLE>
</div>
</BODY>
</HTML>
关于我可能做错的任何想法?如果这是一个新手问题,我很抱歉,我只是在调整方向并对其进行故障排除。任何帮助将不胜感激。
答案 0 :(得分:0)
替换
if ((!$_POST[to])) {
带
if (!isset($_POST['to'])) {
如果您在更改此行后没有看到任何内容,请在此之前写下print_r($_POST);exit;
条件。