我在我的客户网站上创建一个位置,让他们发布业务空缺职位。如果他们发布后出错,我想给他们编辑这个职位的选项。更新后使用php mysql
我的问题是我该如何做到这一点。或者更好的是,我怎样才能从我的数据库中提取信息,以便我可以编辑/保存它?
这是我曾尝试:
为了让事情开始,这里是我的数据库的截图。
phpMyAdmin数据库该表被称为“聘用”没有引号。
我使用3个文件/页面,试图得到这个更新。 首先是所谓的修改 - employment.php
<?php
$title = 'Modify Employment Opportunities';
$page_description = "We offer a complete dock service, rip rap installations, barge service, and custom built breakwaters.";
$thisPage="employment";
include_once($_SERVER['DOCUMENT_ROOT']."/admin/adminheader.php");
include($_SERVER['DOCUMENT_ROOT'] . "/connections/dbconnect.php");
/* be safe, not sorry */
foreach ($_REQUEST as $k => $v) {
$_REQUEST[$k] = mysql_real_escape_string($v);
}
/* take cat from url if exists */
$category = @$_REQUEST["category"] ? $_REQUEST["category"] : null;
$images = mysql_query(
$category ?
sprintf(
"SELECT * FROM hire WHERE data_type = '%s'",
$category
) :
"SELECT * FROM hire"
);
if ($images) {
$total = mysql_num_rows($images);
if ($total) {
$per = 4;
$page = @$_REQUEST["page"] ? $_REQUEST["page"] : 1;
$pages = ceil($total/$per);
}
mysql_free_result($images);
}
?>
misc code...
<section class="grid_8">
<ul class="clearfix">
<?php
if ($category) {
$images = mysql_query(sprintf(
"SELECT * FROM hire WHERE data_type = '%s' ORDER BY id DESC LIMIT %d, %d",
$category, ($page - 1) * $per, $per
));
} else $images = mysql_query(sprintf(
"SELECT * FROM hire ORDER BY id DESC LIMIT %d, %d",
($page - 1) * $per, $per
));
while ($image=mysql_fetch_array($images))
{
?>
<li data-id="id-<?=$image["id"] ?>">
<article class="box white-bg">
<h2 class="red3-tx"><?=$image["title"] ?> <span class="date-posted blue2-tx"><?=$image["date"] ?></span></h2>
<div class="dotline"></div>
<p class="blue3-tx"><?=$image["description"] ?><br />
<br />
For more information please call ###-###-####.</p>
<h4 class="btn-green"><a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/admin/remove-job-post.php?value=<?=$image["id"] ?>">Delete</a></h4>
<h4 class="btn-green"><a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/admin/update-employment.php?value=<?=$image["id"] ?>">Update</a></h4>
</article>
</li>
<?php
}
?>
下面是截图什么上面的样子:
因此,通过使用这行代码:
<h4 class="btn-green"><a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/admin/update-employment.php?value=<?=$image["id"] ?>">Update</a></h4>
我点击更新按钮,它找到帖子的ID号码。 通过点击更新按钮,它会带我到文件#2“update-emploment.php” 我希望此页面可以从原始作业帖子中引入数据,以便我可以编辑和保存信息。 这是我迷路的地方。 这里是我的更新employment.php代码
<?php
$title = 'Admin Employment Opportunities';
$page_description = "Add description in here.";
$thisPage="employment";
include_once($_SERVER['DOCUMENT_ROOT']."/admin/adminheader.php");
include($_SERVER['DOCUMENT_ROOT'] . "/connections/dbconnect.php");
/* be safe, not sorry */
foreach ($_REQUEST as $k => $v) {
$_REQUEST[$k] = mysql_real_escape_string($v);
}
/* take cat from url if exists */
$category = @$_REQUEST["category"] ? $_REQUEST["category"] : null;
$images = mysql_query(
$category ?
sprintf(
"SELECT * FROM hire WHERE data_type = '%s'",
$category
) :
"SELECT * FROM hire"
);
if ($images) {
$total = mysql_num_rows($images);
if ($total) {
$per = 4;
$page = @$_REQUEST["page"] ? $_REQUEST["page"] : 1;
$pages = ceil($total/$per);
}
mysql_free_result($images);
}
?>
misc code....
<form method="post" action="update-hire.php">
<input type="hidden" name="ud_id" style="width: 100%" value="<? echo "$id"; ?>" />
<div class="grid_6 botspacer60 ">
Position Title: <input type="text" name="ud_title" value="<?php echo "$title"; ?>"/>
<br /><br />
Date Posted: <input type="text" name="ud_date" value="<? echo "$date"; ?>"/>
<br /><br />
Position Details:<br />
<textarea name="ud_description" rows="8"><?php echo str_replace("<br />",chr(13),$des); ?><? echo "$description"; ?></textarea>
</div>
<div class="grid_12">
<input type="submit" value="Update" class="button orange" /> <div class="float-right"><input type="button" name="Cancel" value="Cancel" class="button orange" onclick="window.location = '/admin' " /></div>
</div></form>
是获取呼应了作业后的唯一部分是标题,没有称号,我的数据库,但页面的标题。见图片:
然后为形式的行动我使用的文件#3: 行动=“更新hire.php
<?php
include($_SERVER['DOCUMENT_ROOT'] . "/connections/dbconnect.php");
$ud_id = $_POST['ud_id'];
$ud_date = $_POST['ud_date'];
$ud_title = $_POST['ud_title'];
$ud_description = $_POST['ud_description'];
$ud_description = nl2br(htmlspecialchars($_POST['description']));
// Insert record into database by executing the following query:
$query="UPDATE hire SET title='$ud_title', description='$ud_description', date='$ud_date' "."WHERE id='$ud_id'";
$retval = mysql_query($sql);
echo "The position has been updated.<br />
<a href='modify-employment.php'>Update another position.</a><br />";
mysql_close();
?>
我很新的PHP和努力我自己学习,但我花了一天的时间试图让这个工作,所以我想我会看到如果有人一个堆栈可以帮助我,因为我在过去发现了一些有帮助的人在这里,如果有人可以帮助我将不胜感激。谢谢!
当您尝试更新时收到的错误是什么? – Roger