簡體   English   中英

更新查詢不適用於php

[英]Update query not working in php

我已經在表格(分數)中過濾了texbox中的值,但是我想通過更改其中的值來更新它,然后單擊update。

任何人都可以幫助我的代碼..我想更新(texboxes)中的值,但是我的代碼無法正常工作,任何人都可以幫助我找到與程序混淆的代碼嗎?

php代碼:

<?php
if(isset($_POST['update'])){
//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='$u2id'");
//2
mysql_query("UPDATE score SET score1='$u2score1', score2='$u2score2', total='$u2total' WHERE id='$u2id'");
}
?>

html代碼:

<form method="post" id="frm" name="frm" action="" />
<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" />
</form>

在您的提交按鈕中:

<input type="submit" value="update" />

您給了它一個值,但沒有名字。 如果將其更改為:

<input type="submit" name="update" value="yespleasedososir" />

它最終將在您的帖子中

有幾點想法:1.您是否回顯了sql語句以查看得到的結果? 2.嘗試在每個列名之前和之后添加波浪號符號,例如score1 ='whatever'。 3.您確實應該使用mysqli statemnts。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM