所以我试图让这个PHP代码显示一个textarea并提交按钮,这样用户就可以提交插入数据库的bio。我对此代码有一些问题:
由于某种原因,文本区域填充的是实际表单HTML而不是空白框,因此显示为:
<form action='page-bio.php' method='post'>
<textarea name='author_bio' value=<input type='hidden' name='hidden' value=
<input type='submit' name='update' value=update
</form>.
我正在使用wordpress,所以这是一个php模板,但我想知道这段代码是否能正确获取当前用户并将用户的bio插入数据库中用户的bio字段?我有一种感觉它不会,但我无法分辨,因为我仍然无法显示提交按钮。
<?php
$con = mysql_connect("localhost","XXXX","XXXX");
if (!$con){
die("can not connect: " . mysql_error());
}
mysql_select_db("i5412",$con);
// Get the current user's info
$current_user = wp_get_current_user();
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE wp_usermeta SET author_bio='".$_POST['author_bio']."'WHERE
user_id=$current_user and author_bio='".$_POST['hidden']."'";
mysql_query($UpdateQuery, $con);
}
$sql = "SELECT * FROM wp_usermeta";
$myData = mysql_query($sql,$con);
while($record = mysql_fetch_array($myData)){
echo "<form action='page-bio.php' method='post'>";
echo "<textarea name='author_bio' cols='10' rows='10' value=" . $record['author_bio'];
echo "<input type='hidden' name='hidden' value=" . $record['author_bio'];
echo "<input type='submit' name='update' value=update";
echo "</form>";
}
mysql_close($con);
?>
答案 0 :(得分:0)
您忘记关闭一半输入标记,例如您错过结尾的echo "<input type='submit' name='update' value=update";
&gt;
答案 1 :(得分:0)
您需要更改以下行:
echo "<textarea name='author_bio' cols='10' rows='10' value=" . $record['author_bio'];
echo "<input type='hidden' name='hidden' value=" . $record['author_bio'];
echo "<input type='submit' name='update' value=update";
要
echo "<textarea name='author_bio' cols='10' rows='10'>" . $record['author_bio'] . "</textarea>";
echo "<input type='hidden' name='hidden' value='" . $record['author_bio']. "'>";
echo "<input type='submit' name='update' value='update'>" ;