我的代码在搜索后不会更新

时间:2014-01-28 23:37:49

标签: php html mysql

任何人都可以帮我找到导致我的代码不起作用的代码吗?我的代码不会更新...我已经在3小时内调试这段代码已经不能解决它了:( ...我需要你的帮助。

php代码:

<?php
if(isset($_GET['gogo'])){
include('include/connect.php');
$batchcode = $_GET['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
if($sql) {
    while($rows = mysql_fetch_array($sql)){
        $id[] = $rows['id'];
        $name[] = $rows['name'];
        $score1[] = $rows['score1'];
        $score2[] = $rows['score2'];
        $other_qual[] = $rows['score3'];
        $interview[] = $rows['score4'];
        $total[] = $rows['total'];
    }
}
}
?>
<?php
if(isset($_POST['update'])){
include('include/connect.php');
//1
$u1id = $_POST['id1'];
$u1name = $_POST['name1'];
$u1score1 = $_POST['optA1'];
$u1score2 = $_POST['optB1'];
$u1other_qual = $_POST['other_qual1'];
$u1interview = $_POST['interview1'];
$u1total = $_POST['total1'];
//2
$u2id = $_POST['id2'];
$u2name = $_POST['name2'];
$u2score1 = $_POST['optA2'];
$u2score2 = $_POST['optB2'];
$u2other_qual = $_POST['other_qual2'];
$u2interview = $_POST['interview2'];
$u2total = $_POST['total2'];
//1
mysql_query("UPDATE score SET score1='$u1score1', score2='$u1score2', total='$u1total' WHERE id='$u1id'");
//2
mysql_query("UPDATE score SET score1='$u2score1', score2='$u2score2', total='$u2total' WHERE id='$u2id'");

header("Location: index.php");
}
?>

html代码:

<form method="get">
<form method="post">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="gogo" /><br />
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>
<td>
Name: <br />
<input type="text" name="name1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" readonly /> <br />
<input type="text" name="name2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" readonly /> <br />
</td>
<td>
Score 1: <br />
<input type="text" name="optA1" value="<?php if(empty($score1[0])){$score1[0] = array(NULL);}else{echo $score1[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optA2" value="<?php if(empty($score1[1])){$score1[1] = array(NULL);}else{echo $score1[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Score 2: <br />
<input type="text" name="optB1" value="<?php if(empty($score2[0])){$score2[0] = array(NULL);}else{echo $score2[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optB2" value="<?php if(empty($score2[1])){$score2[1] = array(NULL);}else{echo $score2[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Other Qualification: <br />
<input type="text" name="other_qual1" value="<?php if(empty($other_qual[0])){$other_qual[0] = array(NULL);}else{echo $other_qual[0];} ?>" readonly /> <br />
<input type="text" name="other_qual2" value="<?php if(empty($other_qual[1])){$other_qual[1] = array(NULL);}else{echo $other_qual[1];} ?>" readonly /> <br />
</td>
<td>
Interview: <br />
<input type="text" name="interview1" value="<?php if(empty($interview[0])){$interview[0] = array(NULL);}else{echo $interview[0];} ?>" readonly /> <br />
<input type="text" name="interview2" value="<?php if(empty($interview[1])){$interview[1] = array(NULL);}else{echo $interview[1];} ?>" readonly /> <br />
</td>
<td>
Total: <br />
<input type="text" name="total1" value="<?php if(empty($total[0])){$total[0] = array(NULL);}else{echo $total[0];} ?>" readonly onKeyUp="optTotal1()" /> <br />
<input type="text" name="total2" value="<?php if(empty($total[1])){$total[1] = array(NULL);}else{echo $total[1];} ?>" readonly onKeyUp="optTotal2()" /> <br />
</td>
</tr>
</table>
<input type="submit" value="update" name="update" />
</form>
</form>

2 个答案:

答案 0 :(得分:1)

您不能同时进行GET和POST。使用其中一个..

在您的HTML中删除<form method="get">和相应的</form>,然后使用POST。 (<form method="post">

请参阅:Post and get at the same time in php

然后在PHP中,将GET更改为POST,如下所示:

if(isset($_POST['gogo'])){
include('include/connect.php');
$batchcode = $_POST['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
...

修改

或者,您可以保持您的PHP代码与您拥有的相同,只需在HTML中创建2个单独的表单,使用GET的搜索表单和使用{{1}的其他表单}

所以HTML就是这样:

POST

答案 1 :(得分:0)

如果您的代码不会更新,那么您很可能正在更新错误的文件。确保您正在更新服务器上的文件,甚至更好地更新本地驱动器上的文件,然后将它们上载到服务器。

检查您是否有权上传到正确的位置。可能因为权限不佳而导致上传失败。