您在第3行的SQL语法'WHERE BapID ='1 /'中出错

时间:2014-03-31 18:37:49

标签: php html mysql sql

帮助。我不知道在哪里寻找错误。

这是错误: 您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在附近使用' WHERE BapID'在第3行

<?php  
    $conn = mysql_connect('localhost', 'root', '');
     if (!$conn)
    {
     die('Could not connect:' . mysql_error());
    }
    mysql_select_db('RMS', $conn);


$id = $_REQUEST['BapID'];

$result = mysql_query('SELECT * FROM baptism WHERE BapID');
$row = mysql_fetch_array($result);
if (!$result)
    {
    die("Error: Data not found..");
    }

$FirstName=$row['FirstName'];
$MiddleName=$row['MiddleName'];
$LastName=$row['LastName'];
$Father=$row['Father'];
$Mother=$row['Mother'];
$Datebirth=$row['Datebirth'];  
$Birthplace=$row['Birthplace'];
$Datebaptism=$row['Datebaptism'];
$ministerbaptism=$row['Ministerbaptism'];  
$Sponsor=$row['Sponsors'];

if(isset($_POST['save']))
{
    $firstname_save = $_POST['firstname'];
    $middlename_save = $_POST['middlename'];
    $lastname_save = $_POST['lastname'];
    $father_save= $_POST['father'];
    $mother_save= $_POST['mother'];
    $datebirth_save=$_POST['datebirth'];
    $birthplace_save=$_POST['birthplace'];
    $datebap_save=$_POST['datebaptism'];
    $minister_save=$_POST['ministerbaptism'];
    $sponsor_save=$_POST['sponsors'];

    mysql_query("UPDATE baptism SET FirstName='$firstname_save', MiddleName='$middlename_save', LastName='lastname_save',   Father='$father_save',
    Mother='$mother_save', Datebirth='$datebirth_save', Birthplace='$birthplace_save',
    Datebaptism='$datebap_save', Ministerbaptism='$minister_save', Sponsors='$sponsor_save', WHERE BapID")
    or die(mysql_error()); 
    echo "Updated!<br />";
    echo "<a href=baptismal.php>Go back to Records</a><br />";
}
mysql_close($conn);
?>
<style>
tr
{
text-align:left;
}
#submit{
text-align:right;
}
</style>
<body>
<form method="post">
<table>
<th>First Name:</th><th><input type="text" name="firstname" value="<?php echo $FirstName; ?>"/></br></th>
<tr>
<th>Last Name:</th><th><input type="text" name="middlename" value="<?php echo $MiddleName; ?>"/></br></th>
<tr>
<th>Middle Name:</th><th><input type="text" name="lastname" value="<?php echo $LastName; ?>"/></br></th>
<tr>
<th>Father:</th><th><input type="text" name="father" placeholder="Father's Name" value="<?php echo $Father ?>"/></br></th>
</tr><tr>
<th>Mother:</th><th><input type="text" name="mother" placeholder="Mother's Name" value="<?php echo $Mother ?>"/></br></th>
</tr><tr>
<th>Date of Birth:</th><th><input type="date" name="datebirth" value="<?php echo $Datebirth ?>"/></br></th>
</tr><tr>
<th>Place of Birth:</th><th><input type="text" name="birthplace" placeholder="Place of Birth"value="<?php echo $Birthplace ?>"/></br></th>
</tr><tr>
<th>Date of Baptism:</th><th><input type="date" name="datebaptism"value="<?php echo $Datebaptism ?>"/></br></th>
</tr><tr>
<th>Minister of Baptism:</th><th><input type="text" name="ministerbaptism" placeholder="Minister"value="<?php echo $ministerbaptism ?>"/></br></th>
</tr><tr>
<th>Sponsors:</th><th><input type="text" name="sponsors" placeholder="Sponsor"value="<?php echo $Sponsor ?>"/></br></th>
</tr>
<th></th><th id=submit><input type="submit" name="save" value="Save"/></th>
</table>
</body>

2 个答案:

答案 0 :(得分:0)

对于BapID会是什么?

UPDATE baptism
SET FirstName='$firstname_save',
              MiddleName='$middlename_save',
                         LastName='lastname_save',
                                  Father='$father_save',
                                         Mother='$mother_save',
                                                Datebirth='$datebirth_save',
                                                          Birthplace='$birthplace_save',
                                                                     Datebaptism='$datebap_save',
                                                                                 Ministerbaptism='$minister_save',
                                                                                                 Sponsors='$sponsor_save'
WHERE BapID = ''; <<----- Add the searching value here 

答案 1 :(得分:0)

此处的问题出在您的UPDATE语句中。错误显示为right syntax to use near 'WHERE BapID',因此您正在WHERE子句之前查找SQL语句的错误。

如果我们查看导致它的查询,我们会看到Sponsors='$sponsor_save', WHERE,我们可以从中查看问题。 SQL不接受列表上的尾随逗号,因此您希望从WHERE之前删除该逗号。

除此之外,SQL很好。