Php 将文本框内的文本传递到单击时的页面也传递多个值
我正在尝试传递Php 将文本框内的文本传递到单击时的页面也传递多个值,php,html,Php,Html,我正在尝试传递中的文本并在我的sql数据库中更新它,但是我确实希望中已经存在一些文本,正如您在图像中看到的那样,因此当我单击按钮或链接时,我无法将文本框中的文本传递到编辑注释.php,我还必须传递变量$note\u id index.php $note_query = mysql_query("SELECT * FROM `notes` WHERE `id` = $note_id AND `user_id`='$my_id'"); while ($run_note = mysql_fetch_a
中的文本并在我的sql数据库中更新它,但是我确实希望
中已经存在一些文本,正如您在图像中看到的那样,因此当我单击按钮或链接时,我无法将文本框中的文本传递到编辑注释.php
,我还必须传递变量$note\u id
index.php
$note_query = mysql_query("SELECT * FROM `notes` WHERE `id` = $note_id AND `user_id`='$my_id'");
while ($run_note = mysql_fetch_assoc($note_query)) {
$note_text = $run_note['text'];
$note_date = $run_note['Note_added_dat'];
}
echo $edit_text = "<textarea id='note'>$note_text</textarea><br><br>";
echo <a href='edit_note.php?note=$note_id&edit=$edit_text>EDIT</a>/*click this to update note*/
if(isset($_GET['note']) && !empty($_GET['note'])) {
$my_id = $_SESSION['user_id'];
echo $note_id=$_GET['note'];
echo $edit_note = $_GET['edit'];
}
if (mysql_query("UPDATE `notes` SET `text`='$edit_note',`Note_added_dat`= now() WHERE `note_id` ='$note_id' AND `user_id` = '$my_id'")) {
{
echo 'Note has been Edited';
}
}
输出
试试这样的方法:
<?php
$note_query = mysql_query("SELECT * FROM `notes` WHERE `id` = $note_id AND `user_id`='$my_id'");
while ($run_note = mysql_fetch_assoc($note_query)) {
$note_text = $run_note['text'];
$note_date = $run_note['Note_added_dat'];
}
?>
<form method="GET" action="edit_note.php">
<input type="hidden" name="note" value="<?php echo $note_id;?>">
<textarea name="edit"><?php echo $note_text;?></textarea>
<input type="submit" value="Edit">
</form>
虽然这个代码片段可以解决这个问题,但“代码外”确实有助于提高文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。还请尽量不要用解释性注释挤满你的代码,这会降低代码和解释的可读性!感谢这段代码真的做到了这一点,我可以更新我的数据库,还可以传递这两个变量。你可以解释一下从
到
的过程吗
<?php
$default_text = "Something";
$note_query = mysql_query("SELECT * FROM `notes` WHERE `id` = $note_id AND `user_id`='$my_id'");
while ($run_note = mysql_fetch_assoc($note_query)) {
$note_id = $run_note['id'];
$note_text = $run_note['text'];
$note_date = $run_note['Note_added_dat'];
}
if( isset($note_text) )
echo $edit_text = "<textarea id='note'>$note_text</textarea><br><br>";
else
echo $edit_text = "<textarea id='note'>$default_text</textarea><br><br>";
echo "<a href='edit_note.php?note=$note_id&edit=$edit_text>EDIT</a>"; /*click this to update note*/
?>
edit_note.php
<?php
if(isset($_GET['note']) && !empty($_GET['note'])) {
$my_id = $_SESSION['user_id'];
echo $note_id=$_GET['note'];
echo $edit_note = str_replace("\r\n", "<br>", $_GET['edit']);
}
if (mysql_query("UPDATE `notes` SET `text`='$edit_note',`Note_added_dat`= now() WHERE `note_id` ='$note_id' AND `user_id` = '$my_id'")) {
{
echo 'Note has been Edited';
}
}
?>