返回信息流我先把代码贴出来,然后请教大家问题哈:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Delete a Blog Entry</title>
</head>
<body>
<h1>Delete an Entry</h1>
<?php // Script 12.8 - delete_entry.php
/* This script deletes a blog entry. */
// Connect and select:
$dbc = mysql_connect('127.0.0.1', 'root', '');
mysql_select_db('myblog', $dbc);
if (isset($_GET['id']) && is_numeric($_GET['id']) ) { // Display the entry in a form:
// Define the query:
$query = "SELECT title, entry FROM entries WHERE entry_id={$_GET['id']}";
if ($r = mysql_query($query, $dbc)) { // Run the query.
$row = mysql_fetch_array($r); // Retrieve the information.
// Make the form:
print '<form action="delete_entry.php" method="post">
<p>Are you sure you want to delete this entry?</p>
<p><h3>' . $row['title'] . '</h3>' .
$row['entry'] . '<br />
<input type="hidden" name="id" value="' . $_GET['id'] . '" />
<input type="submit" name="submit" value="Delete this Entry!" /></p>
</form>';
} else { // Couldn't get the information.
print '<p style="color: red;">Could not retrieve the blog entry because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}
} elseif (isset($_POST['id']) && is_numeric($_POST['id'])) { // Handle the form.
// Define the query:
$query = "DELETE FROM entries WHERE entry_id={$_POST['id']} LIMIT 1";
$r = mysql_query($query, $dbc); // Execute the query.
// Report on the result:
if (mysql_affected_rows($dbc) == 1) {
print '<p>The blog entry has been deleted.</p>';
} else {
print '<p style="color: red;">Could not delete the blog entry because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}
} else { // No ID received.
print '<p style="color: red;">This page has been accessed in error.</p>';
} // End of main IF.
mysql_close($dbc); // Close the connection.
?>
</body>
</html>
我想请问,这里面form表单提交对页面产生了什么样的影响,是会对$_POST[]数组赋值,同时删除$_GET[]数组里的值么?
点击form表单的subumit后,页面会发生怎样的变化呢?
谢谢大家!
这是一条镜像帖。来源:北邮人论坛 / www-technology / #15399同步于 2012/1/30
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖
请教一个PHP的小白问题,谢谢
herenow
2012/1/30镜像同步8 回复
订阅后,新回复会通过你的通知中心匿名送达。
8 条回复
是对$_post[]赋值,但是不是删除$_GET[]。动作是这个:// Define the query:
$query = "DELETE FROM entries WHERE entry_id={$_POST['id']} LIMIT 1";
$r = mysql_query($query, $dbc); // Execute the query.
submit按钮,如果form的method是get那就是对$_GET赋值,如果是post则是对$_POST赋值。,form的submit对网页本身没有任何影响
【 在 herenow (太极小子) 的大作中提到: 】
: 我先把代码贴出来,然后请教大家问题哈:
: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
: ...................
<form action="delete_entry.php" method="post">
<input type="hidden" name="id" value="' . $_GET['id'] . '" />
感谢LS各位,我的疑问是这样的,当我第一次打开这个页面的时候,会根据这个php脚本生成一个html页面在浏览器上显示出来,当我提交subumit以后,php会再次生成一个新的页面显示吧?
第一次浏览器用get页面逻辑走if(ISSET(_GET))分支,当用户submit后浏览器用post,页面逻辑走if(ISSET(_POST))
【 在 herenow 的大作中提到: 】
: 感谢LS各位,我的疑问是这样的,当我第一次打开这个页面的时候,会根据这个php脚本生成一个html页面在浏览器上显示出来,当我提交subumit以后,php会再次生成一个新的页面显示吧?
【 在 oceanheart 的大作中提到: 】
: 第一次浏览器用get页面逻辑走if(ISSET(_GET))分支,当用户submit后浏览器用post,页面逻辑走if(ISSET(_POST))
: 【 在 herenow 的大作中提到: 】
: : 感谢LS各位,我的疑问是这样的,当我第一次打开这个页面的时候,会根据这个php脚本生成一个html页面在浏览器上显示出来,当我提交subumit以后,php会再次生成一个新的页面显示吧?
: ...................
谢谢!那用户submit后,服务器端需要从新生成页面,再发送给浏览器显示吧?
当然是了
【 在 herenow 的大作中提到: 】
:
: 【 在 oceanheart 的大作中提到: 】
: : 第一次浏览器用get页面逻辑走if(ISSET(_GET))分支,当用户submit后浏览器用post,页面逻辑走if(ISSET(_POST))
: ...................
【 在 oceanheart 的大作中提到: 】
: 当然是了
: 【 在 herenow 的大作中提到: 】
: :
: ...................
所以,第二次生成html页面的时候,会再一次运行这个php脚本么?如果运行,就会从第一行代码开始运行,这样,第一个条件判断中的$_GET[]就为空了是么?如果为空,是因为submit么?
呵呵,问的有点混乱,望包涵哈,非常感谢!