您好我是网络开发新手。我有一个提交php页面,它从以前的表单页面提交数据,并显示提交确认信息。但是现在我要求用户在提交SQL之前再输入2个东西(名称和房间号),所以......以前的表格和名称的信息,房间号码将一起插入到SQL中。我想在同一页面内处理这个提交,但是对于新添加的2个数据(名称和房间号)我不想做一个单独的submit(),因为我不希望页面刷新,
我该怎么办?如何将输入标记(Cname)中的值应用于$ Cname?没有刷新页面?这是我的代码:
...
<head>
<?php
$T1comment1 = $_POST['T1comment1'];//these are from previous form
$T1comment2 = $_POST['T1comment2'];//these are from previous form
$T1comment3 = $_POST['T1comment3'];//these are from previous form
$T1comment4 = $_POST['T1comment4'];//these are from previous form
$item_1 = $_POST['item_1'];//these are from previous form
$item_2 = $_POST['item_2'];//these are from previous form
$item_3 = $_POST['item_3'];//these are from previous form
$item_4 = $_POST['item_4'];//these are from previous form
$Cname = $_POST['Cname'];
$CRnumber = $_POST['CRnumber'];
?>
</head>
<body>
<div>
<form method="POST" name="namdAndRm" id="namdAndRm" action="<?php echo $PHP_SELF;?>" >
<input type="text" id="Cname" name="Cname" value="your name here"></input>
<input type="text" id="CRnumber" name="CRnumber" value="room no."></input>
</form>
</div>
<div>
<div class="Back"></div>
<div class="submit" onclick="goSubmit();"></div>
</div>
<script type="text/javascript">
function goSubmit(){
<?php
$Cname = $_POST['Cname']; //is this the right way to do it?
$CRnumber = $_POST['CRnumber']; // I tested a lot, seams direct "=" is not working...
$SqlStatement = "INSERT INTO T3survey (T1item_1, T1comment1, T1item_2, T1comment2, T1item_3, T1comment3, T1item_4, T1comment4, Cname, CRnumber, day) VALUES ('$item_1', '$T1comment1', '$item_2', '$T1comment2', '$item_3', '$T1comment3', '$item_4', '$T1comment4', '$Cname', '$CRnumber', NOW())";
$result = mysql_query($SqlStatement,$connection);
if (!$result){ die("Error " . mysql_errno() . " : " . mysql_error());}
?>;
};
</script>
</body>
</html>
答案 0 :(得分:0)
您需要做的就是在表单中创建一堆隐藏字段,如下所示:
<input type='hidden' name ='T1comment1' value='<?php $T1comment1;?>'>
<input type='hidden' name ='T1comment2' value='<?php $T1comment2;?>'>
<input type='hidden' name ='T1comment3' value='<?php $T1comment3;?>'>
<input type='hidden' name ='T1comment4' value='<?php $T1comment4;?>'>