更新mysql表中的值

时间:2012-02-06 08:33:13

标签: php mysql

我想编辑表格中的旧值

$row=mysql_fetch_row($res); //get two values in a row from mysql

$value来自$_GET['value'] 并以下列形式使用

<form action="renew.php?value='.$value.'" method="POST">
    Enter your value:  <br/>
    <input type="text" name="firstvalue" size="30" value="'.$row[0].'"/><br/>
    Enter another value:<br/>
    <textarea name="secondvalue" col="10">'.$row[1].'</textarea><br/>
    <input type="submit" value="Done!"/>
</form>

我想发布此表单,然后使用新的firstvalue和secondvalue更新mysql表中的旧值。我现在被困住了。

在renew.php中,我试试这个

$oldvalue=$_GET['value'];
print_r($oldvalue);
$newval1=$_POST['secondvalue'];
$newval2=$_POST['firstvalue']; // An unexpected syntax error for T_VARIABLE here

$query=sprintf("UPDATE tebo SET value1='%s',value2='%s' WHERE value1='%s' LIMIT 1",
               $newval1,$newval2,$oldvalue);
mysql_query($query) or die("Unable to update the specified data. ".mysql_error());

2 个答案:

答案 0 :(得分:0)

你忘记了;在波纹管线上

$newval1=$_POST['secondvalue'];
$newval2=$_POST['firstvalue']; 

答案 1 :(得分:0)

$oldvalue=$_GET['value'];

$newval1=$_POST['secondvalue'];
$newval2=$_POST['firstvalue']; 

$query="UPDATE tebo SET value1='".$newval1."',value2='".$newval2."' WHERE value='".$oldvalue."' ";
mysql_query($query) or die("Unable to update the specified data. ".mysql_error());