2014-03-31 33 views
0

幫助。我不知道在哪裏尋找錯誤。您的SQL語法'WHERE BAPID ='1 /''第3行有錯誤

這是錯誤: 您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法在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> 
+0

WHERE BAPID是什麼?你需要一些東西來比較.. –

+1

擺脫逗號之前(看似沒用)'WHERE BAPID' –

+0

我想它應該在哪裏'BAPID = $ id' –

回答

0

會有什麼=到BapID使用近「WHERE 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

'WHERE ;'是完全有效的SQL。 –

0

這裏的問題在你的UPDATE語句中。該錯誤說right syntax to use near 'WHERE BapID',所以你正在WHERE條款之前尋找與你的SQL語句錯誤。

如果我們看看導致它的查詢,我們看到Sponsors='$sponsor_save', WHERE,從中我們可以看到問題。 SQL不接受列表中的尾隨逗號,因此您想從WHERE之前刪除該逗號。

除此之外,SQL是好的。

相關問題