[英]PHP line goes downwards after update to database
因此,如果我在文本框中輸入文本,則按提交按鈕,將數據發送到update.php,將update.php發送數據到我的數據庫,然后將update.php重定向回到edit.php,文本框的整個文本都變小了, 有任何想法嗎 ?
Edit.php
<html>
<head></head>
<body>
<form method="post" action="update.php">
Meist<br>
<textarea style="resize:none" cols="100" rows="10" method="post" type="text" id="meist" name="meist"><?php
include_once("connect.php");
$sql = 'SELECT meist FROM content WHERE id=1';
mysql_select_db('fava');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "{$row['meist']}";
}
mysql_close($conn);
?>
</textarea><br>
<input type="submit" value="salvesta"/>
</form>
</body>
</html>
update.php
<?php
// configuration
$dbhost = "localhost";
$dbname = "fava";
$dbuser = "root";
$dbpass = "";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$meist =$_POST["meist"];
$id = 1;
// query
$sql = "UPDATE content SET meist=? WHERE id=?";
$q = $conn->prepare($sql);
$q->execute(array($meist,$id));
echo "Edukalt salvestatud";
header('Refresh: 2; URL=http://localhost/php_sandbox/edit.php');
?>
如果有任何疑問,請發牢騷,因為這很難解釋。
對於初學者,請從內容區域獲取所有PHP代碼。 由於您包含了connect.php文件,因此它實際上是將connect.php的內容放入textarea項目中。 如果connect.php中有換行符(如文件末尾),它將在textarea輸入中創建一個空行。
<html>
<head></head>
<body>
<?php
include_once("connect.php");
$sql = 'SELECT meist FROM content WHERE id=1';
$text = '';
mysql_select_db('fava');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
$text .= "{$row['meist']}";
}
mysql_close($conn);
?>
<form method="post" action="update.php">
Meist<br>
<textarea style="resize:none" cols="100" rows="10" method="post" type="text" id="meist" name="meist">
<?php echo $text; ?>
</textarea><br>
<input type="submit" value="salvesta"/>
</form>
</body>
</html>
請注意,我創建了一個空白的$ text變量,並用字段中想要的數據填充它,完成所有工作后,我們僅在內容中回顯該項目。
這將清理代碼,使您清楚自己在做什么,並確保將流浪換行符植入不需要的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.