contact.php
<div class="block-content collapse in">
<div class="span12">
<?php
if(isset($_POST['submit'])=='Save changes'){
$row=$conn->prepare("SELECT * FROM contact_page WHERE addressline11=? LIMIT
1");
$row->execute(array($_POST['addressline11']));
$q = $conn->prepare("UPDATE contact_page SET contact_content1=?,
contact_content2=?, addressline11=?, addressline22=?, addressline33=?,
tel_no1=?, website1=?, emailid1=?, WHERE id=?");
$q->execute(array($_POST['contact_content1'], $_POST['contact_content2'],
$_POST['addressline11'], $_POST['addressline22'], $_POST['addressline33'],
$_POST['tel_no1'], $_POST['website1'], $_POST['emailid1'], $_GET['id'] ));
echo '<div style="width:72%;"><p style="margin-top: 18px; margin-
left:20px;"><span style="font-weight:bold;vertical-align: top;padding:
12px;">contact_content1:-</span> '.$_POST['contact_content1'].'
<p style="margin-top: 18px; margin-left:20px;"><span style="font-
weight:bold;vertical-align: top;padding: 12px;">contact_content2:-</span>
'.$_POST['contact_content2'].'
<p style="margin-top: 18px; margin-left:20px;"><span style="font-\
weight:bold;vertical-align: top;padding: 12px;">Address Line 11:-</span>
'.$_POST['addressline11'].'
<p style="margin-top: 18px; margin-left:20px;"><span style="font-
weight:bold;vertical-align: top;padding: 12px;">Address Line 22:-</span>
'.$_POST['addressline22'].'
<p style="margin-top: 18px; margin-left:20px;"><span style="font-
weight:bold;vertical-align: top;padding: 12px;">Address Line 33:-</span>
'.$_POST['addressline33'].'
<p style="margin-top: 18px; margin-left:20px;"><span style="font-
weight:bold;vertical-align: top;padding: 12px;">Telephone1 :-</span>
'.$_POST['tel_no1'].'
<p style="margin-top: 18px; margin-left:20px;"><span style="font-
weight:bold;vertical-align: top;padding: 12px;">Website1:-</span>
'.$_POST['website1'].'
<p style="margin-top: 18px; margin-left:20px;"> <span style="font-
weight:bold;vertical-align: top;padding: 12px;">Email Id1:-</span>
'.$_POST['emailid1'];
echo '<p align="left" style="margin-top:10px; padding-left: 20px;
color:blue; text-decoration:none; width:50%; font-weight:bold;"><a
style="color:blue;" href="section2_list.php">Edit More Section 2</a></p>
</div>';
exit;
}
if(!empty($_GET['id'])){
foreach($conn->query("SELECT * FROM contact_page WHERE id='$_GET[id]' LIMIT
1") as $stmt){
echo '<div>
<p>
<form class="form-horizontal" action="" autocomplete="off" method="post"
id="footerform" enctype="multipart/form-data">
<fieldset>
<legend>Footer Section</legend>
<div class="control-group">
<label class="control-label"
for="contact_content1">Contact Content 1</label>
<div class="controls">
<input class="input-xlarge
focused" id="contact_content1" name="contact_content1" type="text" required
value="'.$stmt['contact_content1'].'">
</div>
</div>
<div class="control-group">
<label class="control-label"
for="contact_content2">Contact Content 2</label>
<div class="controls">
<input class="input-xlarge
focused" id="contact_content2" name="contact_content2" type="text" required
value="'.$stmt['contact_content2'].'">
</div>
</div>
<div class="control-group">
<label class="control-label"
for="addressline1">Address line 1</label>
<div class="controls">
<input class="input-xlarge
focused" id="addressline1" name="addressline1" type="text" required
value="'.$stmt['addressline11'].'">
</div>
</div>
<div class="control-group">
<label class="control-label"
for="addressline2">Address line 2</label>
<div class="controls">
<input class="input-xlarge
focused" id="addressline2" name="addressline2" type="text" required
value="'.$stmt['addressline22'].'">
</div>
</div>
<div class="control-group">
<label class="control-label"
for="addressline3">Address line 3</label>
<div class="controls">
<input class="input-xlarge
focused" id="addressline3" name="addressline3" type="text" required
value="'.$stmt['addressline33'].'">
</div>
</div>
<div class="control-group">
<label class="control-label"
for="tel_no">Tel No.</label>
<div class="controls">
<input class="input-xlarge
focused" id="tel_no" name="tel_no" type="text" required
value="'.$stmt['tel_no1'].'">
</div>
</div>
<div class="control-group">
<label class="control-label"
for="website">Website</label>
<div class="controls">
<input class="input-xlarge
focused" id="website" name="website" type="text" required
value="'.$stmt['website1'].'">
</div>
</div>
<div class="control-group">
<label class="control-label"
for="emailid">Email</label>
<div class="controls">
<input class="input-xlarge
focused" id="emailid" name="emailid" type="text" required
value="'.$stmt['emailid1'].'">
</div>
</div>
<div class="form-actions">
<input type="submit" name="submit"
id="submit" class="btn btn-primary" value="Save changes"
onclick="showoutput()">
</div>
</fieldset>
</form>';
}
}
?>
</div>
</div>
</div>
<!-- /block -->
我正在编辑我的表单,但错误即将来临。
带有消息'SQLSTATE [42000]的未捕获异常'PDOException': 语法错误或访问冲突:1064 SQL中有错误 句法;查看与MySQL服务器版本对应的手册 正确的语法使用在第1行''附近的'WHHER id ='2'' G:\ PleskVhosts \ angelsoftweb.com \ angelunitrax.com \ ADMIN \ edit_contact_details.php:175 堆栈跟踪:
#0
G:\ PleskVhosts \ angelsoftweb.com \ angelunitrax.com \ admin \ edit_contact_details.php(175): PDOStatement-&GT;执行(阵列)#1
{main}抛出G:\ PleskVhosts \ angelsoftweb.com \ angelunitrax.com \ admin \ edit_contact_details.php 第175行
答案 0 :(得分:2)
你在set子句中有一个额外的逗号:
emailid1=?, WHERE id=?
正确查询:
UPDATE contact_page SET contact_content1=?,
contact_content2=?, addressline11=?, addressline22=?, addressline33=?,
tel_no1=?, website1=?, emailid1=? WHERE id=?