表格的一页:<?php session_start(); $_SESSION['Business_Ownr']="textfield2"; //textfield 是我用Dreamweaver画的那个文本域。 $_SESSION['On_Site_Manager']="textfield9"; $_SESSION['Business_Name']="textfield"; $_SESSION['Mailing_Address']="textfield5"; $_SESSION['City']="textfield6"; $_SESSION['Zip']="textfield7"; $_SESSION['Phone_Number']="textfield3"; $_SESSION['Cell_Number'e]="textfield4"; $_SESSION['On_Site_Phone']="textfield10"; $_SESSION['Email']="textfield8";?>//这是表格的后半部分,在第二页 <?php $res = mysql_connect("localhost","root","2670242"); if (!$res) { die("Could not connect: ".mysql_error()); } $res = mysql_select_db("pesticide sensitive crop database"); if (!$res) { die("Could not select db: ".mysql_error()); } //插入用户填的后半部分的内容到数据库 $query="INSERT INTO pesticide_sensitive_crop (Crop_Type,Section,Township,Range,Latitude,Longitude,Crop_Location,Acreage,Organic_Certification_Number) VALUES ('". $_GET["select"]."','". $_GET["textfield7"]."','". $_GET["textfield3"]."','". $_GET["textfield6"]."','". $_GET["textfield8"]."','". $_GET["textfield9"]."','". $_GET["textfield10"]."','". $_GET["textfield11"]."','". $_GET["textfield2"]."')"; $result = mysql_query($query); echo $query; if (!$result) { die("Could not query: ".mysql_error()); }?><?php //获取前一页填的表格内容session_start(); //line186 $query = "INSERT INTO pesticide_sensitive_crop (Business_Owner,On_Site_Manager,Business_Name,Mailing_Address,City,Zip,Phone_Number,Cell_Number,On_Site_Phone,Email) VALUES({$_SESSION['Business_Owner']},{$_SESION['On_Site_Manager']},{$_SESSION['Business_Name']},{$_SESSION['Mailing_Address']},{$_SESSION['City']},{$_SESSION['Zip']},{$_SESSION['Phone_Number']},{$_SESSION['Cell_Number']},{$_SESSION['On_Site_Phone']},{$_SESSION['Email']})"; $result = mysql_query($db, $query); //line 189 ?>我在浏览器里打开第一页,按submit转到第二页,可以打开,但是出现以下的错误 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\ting\vineyard\property.php:7) in C:\AppServ\www\ting\vineyard\property.php on line 186Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\ting\vineyard\property.php on line 189 怎么回事啊,大家帮帮忙,急啊!
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\ting\vineyard\property.php on line 1891. 要么你的SQL连接有问题; 2. 要么就是SQL语句有问题。由于我不知道你的189行在哪里,所以无法知道。
text1.php:
<form action="text2.php" methed=post>
ME<input type="text" name="name">
<input type="submit" value="Submit">
</form>
text2.php:
$name=$_POST['name'];
$name2=$_POST['name2'];
if($name)
{
INSERT $name 到数据库里!
}
if($name2)
{
INSERT $name2 到数据库里!
}<form action="text2.php" methed=post>
MEME<input type="text" name2="name2">
<input type="submit" value="Submit">
</form>
先回答第二个问题,你可以submit,然后在后台处理php程序中重定向到显示第二部分的页面。第一个问题,你可以在上面后台处理php程序中就写进数据库;在处理第二部分的php页面中,定位刚才这个记录再插入即可。至于如何定位,可以是通过唯一的标识符ID进行,也可以通过唯一索引来定位。至于如何传递这个定位信息,可以考虑用session/cookie;也可以考虑用?id='12345'这样的URI传递,然后在第二部分页面构造一个hidden表单控件来存储这个id并一并提交。
<?php
session_start();
$_SESSION['name'] = "张三";
$_SESSION['country'] = "中国";
?>这样在跳转到第二个页面后,$_SESSION['name'] 和 $_SESSION['country'] 中的数据仍然存在,可以直接调用,例如:
<?php
session_start();
$query = "insert into `userdata` (`name`, `country`) values ($_SESSION['name'], $_SESSION['country'])";
$result = mysqli_query($db, $query);需要注意的是,如果某个页面中需要用到 $_SESSION[] 数组,必须在使用前调用 session_start() 函数,且某个页面只能调用一次该函数。当不再需要 $_SESSION[] 数组中的值,可以用 session_destroy() 销毁所有当前储存的值,但不会删除变量本身,例如 $_SESSION['name'] 这个变量将仍然存在,但是值被清空了。如果要销毁所有的 session 变量,可以用 $_SESSION = array()。
session_start();
$_SESSION['Business_Ownr']="textfield2"; //textfield 是我用Dreamweaver画的那个文本域。
$_SESSION['On_Site_Manager']="textfield9";
$_SESSION['Business_Name']="textfield";
$_SESSION['Mailing_Address']="textfield5";
$_SESSION['City']="textfield6";
$_SESSION['Zip']="textfield7";
$_SESSION['Phone_Number']="textfield3";
$_SESSION['Cell_Number'e]="textfield4";
$_SESSION['On_Site_Phone']="textfield10";
$_SESSION['Email']="textfield8";?>//这是表格的后半部分,在第二页
<?php
$res = mysql_connect("localhost","root","2670242");
if (!$res) {
die("Could not connect: ".mysql_error());
}
$res = mysql_select_db("pesticide sensitive crop database");
if (!$res) {
die("Could not select db: ".mysql_error());
}
//插入用户填的后半部分的内容到数据库
$query="INSERT INTO pesticide_sensitive_crop (Crop_Type,Section,Township,Range,Latitude,Longitude,Crop_Location,Acreage,Organic_Certification_Number)
VALUES ('". $_GET["select"]."','". $_GET["textfield7"]."','". $_GET["textfield3"]."','". $_GET["textfield6"]."','". $_GET["textfield8"]."','". $_GET["textfield9"]."','". $_GET["textfield10"]."','". $_GET["textfield11"]."','". $_GET["textfield2"]."')";
$result = mysql_query($query); echo $query; if (!$result) {
die("Could not query: ".mysql_error());
}?><?php //获取前一页填的表格内容session_start(); //line186
$query = "INSERT INTO pesticide_sensitive_crop (Business_Owner,On_Site_Manager,Business_Name,Mailing_Address,City,Zip,Phone_Number,Cell_Number,On_Site_Phone,Email)
VALUES({$_SESSION['Business_Owner']},{$_SESION['On_Site_Manager']},{$_SESSION['Business_Name']},{$_SESSION['Mailing_Address']},{$_SESSION['City']},{$_SESSION['Zip']},{$_SESSION['Phone_Number']},{$_SESSION['Cell_Number']},{$_SESSION['On_Site_Phone']},{$_SESSION['Email']})";
$result = mysql_query($db, $query); //line 189
?>我在浏览器里打开第一页,按submit转到第二页,可以打开,但是出现以下的错误
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\ting\vineyard\property.php:7) in C:\AppServ\www\ting\vineyard\property.php on line 186Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\ting\vineyard\property.php on line 189
怎么回事啊,大家帮帮忙,急啊!
2. 要么就是SQL语句有问题。由于我不知道你的189行在哪里,所以无法知道。
$query = "INSERT INTO pesticide_sensitive_crop (Business_Owner,On_Site_Manager,Business_Name,Mailing_Address,City,Zip,Phone_Number,Cell_Number,On_Site_Phone,Email)
VALUES({$_SESSION['Business_Owner']},{$_SESION['On_Site_Manager']},{$_SESSION['Business_Name']},{$_SESSION['Mailing_Address']},{$_SESSION['City']},{$_SESSION['Zip']},{$_SESSION['Phone_Number']},{$_SESSION['Cell_Number']},{$_SESSION['On_Site_Phone']},{$_SESSION['Email']})";
$result = mysql_query($db, $query); //line 189
session 出现问题是因为 session_start() 前面不能有任何输出,你在 $result = mysql_query($query); 这行下面写了 echo $query; 就等于已经向浏览器发送 header,所以出问题了,把 echo $query 删除即可。