gpt4 book ai didi

php - guest_post() 是如何工作的,输出中的显示问题 - 代码末尾附加并提到的图像

转载 作者:行者123 更新时间:2023-11-29 10:17:12 25 4
gpt4 key购买 nike

My Issue:

<?php //sqltest.php

//Part 01 - The first part of the code will establish connection with DB using mysqli method

require_once 'login.php';

$conn = new mysqli($hn,$un,$pw,$db);

if ($conn->connect_error) die ($conn->connect_error);

// Part - 02 - Here is the method to delete some data using query by taking input and later checking using isset

if (isset($_POST['delete']) && isset ($_POST['isbn'])){

$isbn = get_post($conn,'isbn');
$query ="DELETE FROM classics WHERE isbn = '$isbn'";
$result = $conn->query($query);

if (!$result) echo "DELETE failed: $query<br>". $conn->error . "<br><br>";
}

//Part 04 - Here is the method to insert some data using query by taking input by get_post method-(see the last code) and checking using isset

if (isset($_POST['author']) &&
isset($_POST['title']) &&
isset($_POST['category']) &&
isset($_POST['year']) &&
isset($_POST['isbn'])){

$author = get_post($conn,'author');
$title = get_post($conn,'title');
$category = get_post($conn,'category');
$year = get_post($conn,'year');
$isbn = get_post($conn,'isbn');
$query = "INSERT INTO classics VALUES" . "('$author','$title','$category','$year','$isbn')";

$result = $conn->query($query);

if (!$result) echo "INSERT failed: . $query<br> ". $conn->error. "<br><br>";
}

//Part - 05 - FORM handler

echo <<<_END

<form action="sqltest.php"
method="post">
<pre>

Author <input type = "text" name ="author">
Title <input type = "text" name = "title">
Category <input type = "text" name = "category">
Year <input type = "text" name = "year">
ISBN <input type = "text" name = "isbn">

<input type = "submit" value = "ADD RECORD">

</pre>
</form>
_END;

// Part - 06 -A new query for showing the whole classics table from DB

$query = "SELECT * FROM classics";

$result = $conn->query($query);

if(!$result) die ("Database access failed: ". $conn->error);

$rows = $result->num_rows;

for ($j=0; $j<$rows; ++$j){

$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);

// Part - 07 The following html code will take the iput for deleting any entry using isbn - refers to 1st part of the code

echo <<<_END

<pre>

Author $row[0]
Title $row[1]
Category $row[2]
Year $row[3]
ISBN $row[4]

</pre>

<form action = "sqltest.php" method = "post">

<input type ="hidden" name = "delete" value = "yes">
<input type = "hiddden" name = "isbn" value = "$row[4]">
<input type="submit" value = "DELETE RECORD">

</form>
_END;

}

$result->close();
$conn->close();

//Part 08 - actually the code begins from here

function get_post($conn,$var)

{
return $conn->real_eascape_string($_POST[$var]);

//to avoid special charecter
}



?>

/** 代码运行得很好。除了两件事:1.在代码的第 7 部分中,我提到要隐藏 isbn 编号,只显示删除按钮。但在输出中它同时显示数字和按钮。 2. 带有记录字段的框没有设置,这看起来不像预期的那么好 - 我使用了 pre,但仍然显示损坏的输出。**/

最佳答案

对于#1,您在 hiddden 中存在拼写错误(正确的应该是 hidden)。

对于#2,学习如何使用 css style the form 。还学习如何使用html label tag

有些人建议使用表格进行格式化,这不是最佳实践,应该避免。

一般来说,HTML 应该只包含有关内容的信息,CSS 负责内容的呈现。这称为Separation of Concerns .

关于php - guest_post() 是如何工作的,输出中的显示问题 - 代码末尾附加并提到的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49955971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com