0
我想在一个表更新值
$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());
您应该结束了'每一行;'。这就是你得到指定错误的原因。此外,请谷歌SQL注入并做一些事情,以防止它。 'mysql_real_escape_string()'是一个好的开始。 – kapa 2012-02-06 08:35:18
感谢您发现这一点。我的头脑完全搞砸了/ – user1290187 2012-02-06 08:41:32
适合所有人:)。只需要处理SQL注入问题,现在您的代码就是对想要惹恼您网站的人的邀请。 – kapa 2012-02-06 08:48:53