我创建了一个简单的 Web 表单,您可以在其中输入数据,然后将其发布到数据库中,在提交信息时它已正确提交,但是当我在表中查看它时,数据是不可见的。
询问
CREATE TABLE `recipe` (
`id` int(4) NOT NULL auto_increment,
`recipename` varchar(65) NOT NULL default '',
`ingredients` varchar(65) NOT NULL default '',
`instructions` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=0 ;
php代码
<?php
$host="localhost"; // Host name
$username="my username"; // Left empty due to privacy
$password="mypassword"; // Left empty due to privacy
$db_name="mydatabase"; // Left empty due to privacy
$tbl_name="recipe"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$recipe=$_POST['recipename'];
$ingredients=$_POST['ingredients'];
$instructions=$_POST['instructions'];
$sql="INSERT INTO $tbl_name(recipename, ingredients, instructions)VALUES('$recipe', '$ingredients', '$instructions')";
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='recipe.php'>Back to main page</a>";
} else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
网页表格
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>
<form name="form1" method="post" action="insert_ac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td width="71">Recipe name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="recipe"></td>
</tr>
<tr>
<td>Ingredients</td>
<td>:</td>
<td><input name="lastname" type="text" id="ingredients"></td>
</tr>
<tr>
<td>Instructions</td>
<td>:</td>
<td><input name="email" type="text" id="instructions"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
我很想知道是否有人知道数据不可见的原因。
没有数据的表的图像