目前登录的用户必须手动输入他们的名字才能发表评论或发帖,但我想这样做 获取自动插入的html表单字段名称中的用户名。同时用户也无法更改名称字段。
我怎样才能在用户名字段中创建这样的会话,我试过但代码不起作用..
//create the form to submit comments
//you can add more fields, but make sure you add them to the db table and the page, submitcomment.php
echo "
<a name=\"post\">
<div id=\"submitcomment\" class=\"submitcomment\">
<form name=\"submitcomment\" method=\"post\" action=\"submitcomment.php\" onSubmit=\" return form_Validator(this)\">
<table width=\"100%\">
<tr>
<th colspan=\"2\"><h4><span>Leave your comment:</span></h4></th>
</tr>
<th scope=\"row\"><p class=\"req\">Name:</p></th> <td><input type= class=\"form\" tabindex=\"1\" id=\"name\" name=\"name\" /></td> </tr>
<tr>
<th scope=\"row\"><p class=\"opt\">Email:</p></th>
<td><input class=\"form\" tabindex=\"2\" id=\"email\" name=\"email\" /></td>
</tr>
<tr>
<th scope=\"row\"><p class=\"opt\">URL:</p></th>
<td><input class=\"form\" tabindex=\"3\" id=\"url\" name=\"url\" /></td>
</tr>
<tr valign=\"top\">
<th scope=\"row\"><p class=\"req\">Comments:</p><br /></th>
<td><textarea class=\"formtext\" tabindex=\"4\" id=\"message\" name=\"message\" rows=\"10\" cols=\"50\"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type=\"submit\" name=\"post\" class=\"submit\" value=\"Submit Comment\" /><br />
<p>Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted. </p>
<p>In Beta Phase</p>
</td>
</tr>
</table>
<input type=\"hidden\" name=\"tuturl\" value=\"$tuturl\" />
<input type=\"hidden\" name=\"tutid2\" value=\"$tutid2\" />
</form>
</div>
";
}
?>
答案 0 :(得分:0)
<?php
session_start();
// after user logs in successfully
$_SESSION['username']=$username;
// to read it
$username=$_SESSION['username'];
// then store $username in database when inserting comment
?>
答案 1 :(得分:0)
尝试在页面上使用以下代码自动添加名称。
<?php
session_start();
$_SESSION['name']=$name;
$name=$_SESSION['name']; // assign session to name variable
?>
在想要显示名称的任何地方写下$ name。
然后编辑以下代码行
<td><input type= class=\"form\" tabindex=\"1\" id=\"name\" name=\"$name\" readonly=\"readonly\" /></td>