【发布时间】:2013-01-11 10:37:36
【问题描述】:
我正在构建一个自定义 CMS,并且我编写了一个脚本,应该编辑我的数据库中已有的信息。
我之前已经将代码用于不同的数据库,并且它可以正常工作,但我已经更改了索引名称以引用新数据库,现在它无法正常工作。
信息显示在带有“编辑”按钮的页面上,该按钮将用户链接到 html 表单,该表单在文本框中显示所选信息。
在表单中显示信息没有问题,但是一旦按下提交按钮,代码就不会执行它,并且信息没有更新,也没有显示错误消息..
所以我相当确定这其中的某个地方存在问题...(忽略 cmets)
if (isset($_GET['edittimeslot']))
{
$timeslotid = $_GET['timeslotid'];
try
{
$sql = "SELECT timeslotid, Time FROM timeslots WHERE timeslotid = timeslotid" ;
//echo $sql;
$data = $pdo->query($sql);
$timeslots = $data->fetch();
//print_r($acts);
}
catch(PDOException $e)
{
echo "this didnt work" .$e->getMessage() ;
}
$pagetitle = 'Edit your date here';
$timeslotid = $timeslots['timeslotid'];
$time = $timeslots['Time'];
$button = 'Edit timeslot';
include 'timeslot.form.php';
exit();
}
// is all of the requested feilds appropiate
if (isset($_POST['submit']) && $_POST['submit'] == 'Edit timeslot')
{
// get the form data that was posted ready to insert into the stage database
$timeslotid = $_POST['timeslotid'];
$time= htmlspecialchars($_POST['time']);
try
{
// prepare the query to insert data into stages table
$sql = "UPDATE timeslots
SET Time = :Time,
WHERE timeslotid = :timeslotid";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':Time', $time);
$stmt->bindParam(':timeslotid', $timeslotid);
$stmt->execute();
}
catch(PDOException $e)
{
//error message goes here if the insert fails
}
}
HTML:
<!doctype html>
<head>
<style type="text/css">
.container {
width: 800px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
<h1><?php echo $pagetitle;?></h1>
<form action='.' method='post'>
<!-- stage name -->
<p><label for='time'> What is the timeslots you would like to add? 00:00-00:00 </label></p>
<p><input type='text' name='time' id='time' value='<?php echo $time;?>'> </p>
<p><input type='submit' name='submit' value='<?php echo $button;?>'></p>
</form>
</div>
</body>
【问题讨论】:
-
你能把
ini_set('display_error',)`放在页面顶部吗? -
错误显示功能已开启,不显示任何错误。
标签: php sql pdo sql-update