通过php进入时,mysql数据库的问题

时间:2014-03-12 02:48:11

标签: php mysql sql

我想通过PHP在MySQL中创建多个表。第一个表是主表,其中记录了子表的名称,与它们各自的子表链接,并且表名也在PHP代码中定义,因此将数据输入到该表中没有问题。

问题来自第二张表。我会告诉你代码。

第一页,进入主表:

<form action="add.php" align="center" method="GET">
<b><br><br><br>Enter the field: </b>
<input type="text" name="name1" size="30"/>
<input type="submit" name="submit" size="25" value="ok"/> 

我的第二页add.php,用于进入主表并创建一个新表:

<?php
$area=$_GET["name1"];
mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
mysql_query("INSERT INTO main (item_id) values('$area')"); 
mysql_query("CREATE TABLE $area (item VARCHAR(30), budget INT, priority INT)"); 
print ("<h3>Now enter the details of<b> $area</h3>");
?>
<form action="field.php" method="POST">
<b> enter the field:- </b> <input type="text" name="name" size="30"/>
<b> Amount </b> <input type="integer" name="value1" size="10"/>
<b> priority </b> <input type="integer" name="value" size="10"/>
<input type="submit" name="submit" size="25" value="submit"/>

现在第三页,field.php,这里出现错误。第二页中$area(来自第一页)的值与第二页中的点击提交按钮相同:

<?php
$feild=$_GET["name"];
$amount=$_GET["value1"];
$priority=$_GET["value"];
mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
mysql_query("INSERT INTO $area (item, budget, priority) values('$feild',
            '$amount','$priority')");
print ("<h3>Now enter the details of<b> $area</h3>");
?>
<form action="<?php print $_SERVER["PHP_SELF"]; ?>" method="POST">
<b> enter the feild:- </b> <input type="text" name="name" size="30"/>
<b> Amount </b> <input type="integer" name="value1" size="10"/>
<b> priority </b> <input type="integer" name="value" size="10"/>
<input type="submit" name="submit" size="25" value="submit"/>

在第三页中,当我点击提交按钮页面重新加载时,所有以前的数据都会消失,这些数据来自后页。

请让我知道这个错误。我如何解决这个问题请帮助我。

1 个答案:

答案 0 :(得分:0)

来自肖恩的回答

您可以使用以下

<input type="hidden" name="name1" value="<?php echo $area; ?>" />