我的想法很简单:在第一个页面表单中输入一些数据,将它放进数据库中,在点提交后转到第二个页面,并显示出我刚才输入的数据.我的数据能放进数据库,却不能在第二个页面中显示出,不知问题出在哪里,请指教!以下是我的二个页面的源代码,比较长,希望老师们耐心一点啊!我的代码是用dw8生成的!~!<?php require_once('Connections/query.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "importform1")) {
$insertSQL = sprintf("INSERT INTO patient_base (patient_id, name, sex, age, `work`, birthplace, nation, allergichistory, address, phonecode1, phonecode2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['patient_id'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['work'], "text"),
GetSQLValueString($_POST['birthplace'], "text"),
GetSQLValueString($_POST['nation'], "text"),
GetSQLValueString($_POST['allergichistory'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['phonecode1'], "text"),
GetSQLValueString($_POST['phonecode2'], "text")); mysql_select_db($database_query, $query);
$Result1 = mysql_query($insertSQL, $query) or die(mysql_error()); $insertGoTo = "intoexamination.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "importform1")) {
$insertSQL = sprintf("INSERT INTO patient_base (patient_id, name, sex, age, `work`, birthplace, nation, allergichistory, address, phonecode1, phonecode2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['patient_id'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['work'], "text"),
GetSQLValueString($_POST['birthplace'], "text"),
GetSQLValueString($_POST['nation'], "text"),
GetSQLValueString($_POST['allergichistory'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['phonecode1'], "text"),
GetSQLValueString($_POST['phonecode2'], "text")); mysql_select_db($database_query, $query);
$Result1 = mysql_query($insertSQL, $query) or die(mysql_error());
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}mysql_select_db($database_query, $query);
$query_getquery = "SELECT * FROM patient_base";
$getquery = mysql_query($query_getquery, $query) or die(mysql_error());
$row_getquery = mysql_fetch_assoc($getquery);
$totalRows_getquery = mysql_num_rows($getquery);
?><!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">
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "importform1")) {
$insertSQL = sprintf("INSERT INTO patient_base (patient_id, name, sex, age, `work`, birthplace, nation, allergichistory, address, phonecode1, phonecode2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['patient_id'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['work'], "text"),
GetSQLValueString($_POST['birthplace'], "text"),
GetSQLValueString($_POST['nation'], "text"),
GetSQLValueString($_POST['allergichistory'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['phonecode1'], "text"),
GetSQLValueString($_POST['phonecode2'], "text")); mysql_select_db($database_query, $query);
$Result1 = mysql_query($insertSQL, $query) or die(mysql_error()); $insertGoTo = "intoexamination.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "importform1")) {
$insertSQL = sprintf("INSERT INTO patient_base (patient_id, name, sex, age, `work`, birthplace, nation, allergichistory, address, phonecode1, phonecode2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['patient_id'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['work'], "text"),
GetSQLValueString($_POST['birthplace'], "text"),
GetSQLValueString($_POST['nation'], "text"),
GetSQLValueString($_POST['allergichistory'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['phonecode1'], "text"),
GetSQLValueString($_POST['phonecode2'], "text")); mysql_select_db($database_query, $query);
$Result1 = mysql_query($insertSQL, $query) or die(mysql_error());
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}mysql_select_db($database_query, $query);
$query_getquery = "SELECT * FROM patient_base";
$getquery = mysql_query($query_getquery, $query) or die(mysql_error());
$row_getquery = mysql_fetch_assoc($getquery);
$totalRows_getquery = mysql_num_rows($getquery);
?><!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">
解决方案 »
- php 正则高手进,正确用正则检测内部链接或外部链接如何实现?
- 请问下在LOG里面发现一句SQL 这是什么意思呢
- php文件里如何以get方式向远程URL
- php有没有asp.net里像viewstate这种页面级的变量
- PHP如何解压RAR
- 这个表对时间进行查询,如何得到某小时数目的最大值?怎么构造mysql语句? ---> 倾尽所有分数请教!!!
- mysql已经启动,但动行phpmyadmin时,显示“试图连接到 MySQL 服务器,但服务器拒绝连接“,这个要怎么做?
- 下载的问题:保存或打开时都会发生文件名变更的问题.(附代码)
- 网页更新问题,高手请不吝赐教!一定给分!
- 请教一个关于查询效率的问题呗
- curl的应用?
- fckeditor2.5编辑器编辑的内容会多出换行符号 ,怎么办
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>石首市人民医院口腔科信息系统</title>
<link rel="stylesheet" href="emx_nav_left.css" type="text/css" />
<script type="text/javascript">
<!--<style type="text/css">
<!--
#Layer1 {
position:absolute;
width:1101px;
height:1057px;
z-index:1;
left: 45px;
top: 107px;
}
#Layer2 {
position:absolute;
width:304px;
height:439px;
z-index:2;
left: 5px;
top: 36px;
}
#Layer3 {
position:absolute;
width:846px;
height:444px;
z-index:2;
top: 37px;
left: 249px;
}
.STYLE1 {
font-family: "宋体";
font-size: x-large;
}
.STYLE2 {font-size: large}
-->
</style>
</head>
<body onmousemove="closesubnav(event);">
<div class="skipLinks">skip to: <a href="#content">page content</a> | <a href="#pageNav">links on this page</a> | <a href="#globalNav">site navigation</a> | <a href="#siteInfo">footer (site information)</a> </div>
<div id="masthead">
<h1 id="siteName">信息系统</h1>
<div id="Layer1">
<td width="776" bordercolor="#669999" bgcolor="#CCCCCC"><?php echo $_POST['importform1']; ?> </td>
</table>
</div>
</body>
</html>
哈哈……用POST或者GET实现啊
先说第一个错误.第二页(也就是第二个PHP程序)如果想输出第一页的变量,则第一页的这个表单的action必须提交给第二页才行,而这里是提交给了$editFormAction变量,这个变量却指向自身,也就是变量$_SERVER['PHP_SELF'],这个变量就是第一页自己,那么,这种情况下,第二页是接受不到第一页传来的数据的...除非使用session才能跨页传递..
第二个,LZ在第二页里貌似想输出前一个页面输入过来的数据,在第二个程序里用了个echo $_POST['importform1'];,而这个importform1是第一页的表单的名字(有个隐藏域的值也是它).貌似想用表单变量代替表单里的所有变量进行输出...我在我电脑上试了下,结果说该变量未定义..如果LZ想输出变量值,应该单独调用每个变量进行输出..比如性别变量$_POST['sex'],职业变量$_POST['work']...
就看了这么多...
刚从PHP4转到PHP5,感觉POST和GET的变量终于..没法说了...