2012-01-29 3 views
1

G'DaySQL 구문에 오류가 있습니다.

필자가 편집하고 싶은 PHP 페이지가 있는데, 필자는 필자가 왜이 오류가 떠오르는 지 알 수 없다.

SQL 구문에 오류가 있습니다. '= po_postcode ='4060 ', email ='- ', phone ='732997688 ', 팩스 =' 'WHERE id ='1 ''행을 사용하기 위해 MySQL 서버 버전에 해당하는 매뉴얼을 확인하십시오. 1

헬프 나는 절망적이고 정신 나간다. (유사한 코드가 다른 페이지에서 작동하지만이 페이지는 아닙니다.) ....

사람이 도와주세요.

{

<?php 
/* 
EDIT.PHP 
Allows user to edit specific entry in database 
*/ 

// creates the edit record form 
// since this form is used multiple times in this file, I have made it a function that is easily reusable 
function renderForm($id, $name, $po_street, $po_suburb, $po_state, $po_postcode, $email, $phone, $fax, $error) 
{ 
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
<title>Edit Record</title> 
</head> 
<body> 
<?php 
// if there are any errors, display them 
if ($error != '') 
{ 
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; 
} 
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
<title>Edit Record</title> 
</head> 
<body> 

<table width="347" border="0" align="center"> 
    <tr valign="baseline"> 
     <td align="right" nowrap="nowrap"><p align="center"><img src="hartwell_banner.JPG" width="624" height="134" /></p> 
    </tr> 
</table> 
<table align="center"> 
    <tr valign="baseline"> 
     <td width="290" align="right" nowrap="nowrap"><div align="left"><h2 align="left"><p align="left"><a href="contact_insert.php">Enter a New Contact</a></p></h2></div></td> 
    <td width="290" align="center" nowrap="nowrap"><div align="left"><h2 align="center"><p align="center"><a href="index.php">Return to Index</a></p> 
    </h2> 
</div></td> 
    </tr> 
    </table> 


<form action="" method="post"> 
<input type="hidden" name="id" value="<?php echo $id; ?>"/> 
<table align="center"> 
<tr valign="baseline"> 
     <td width="98" align="right" nowrap="nowrap"><div align="left">ID:</div></td>  
     <td width="329"><input type="text" name="id" value="<?php echo $id; ?>" size="40" readonly = "readonly" /> * </td> 
    </tr> 
    <tr valign="baseline"> 
     <td width="98" align="right" nowrap="nowrap"><div align="left">Name:</div></td>  
     <td width="329"><input type="text" name="name" value="<?php echo $name; ?>" size="40" /> * </td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right"><div align="left">Postal Street </div></td> 
     <td><input type="text" name="po_street" value="<?php echo $po_street; ?>" size="40" /> * </td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right"><div align="left">Postal Suburb</div></td> 
     <td><Input type ="text" name="po_suburb" value="<?php echo $po_suburb; ?> " size="30" maxlength="50" >*</td> 
     <tr valign="baseline"> 

    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right"><div align="left">State</div></td> 
     <td><Input type ="text" name="po_state" value="<?php echo $po_state; ?>" size="5" maxlength="3" /> * </td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right"><div align="left">Postal Postcode</div></td> 
     <td><Input type ="text" name="po_postcode" value="<?php echo $po_postcode; ?>" size="5" maxlength="4"/> * </td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right"><div align="left">Email:</div></td> 
     <td><input type="text" name="email" value="<?php echo $email; ?>" size="40" /> * </td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right"><div align="left">Phone:</div></td> 
     <td><input name="phone" type="text" value="<?php echo $phone; ?>" size="12" maxlength="10" /> * </td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right"><div align="left">Fax:</div></td> 
     <td><input name="fax" type="text" value="<?php echo $fax; ?>" size="12" maxlength="10" /></td> 
    </tr> 
    <tr valign="baseline"> 
     <td nowrap="nowrap" align="right">&nbsp;</td> 
     <td> <input type="submit" name="submit" value="Submit"> * Denotes Required Field<?php 
// if there are any errors, display them 
if ($error != '') 
{ 
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; 
} 
?> </td> 
    </tr> 

    <tr valign="baseline"> 
     <td colspan="2" align="right" nowrap="nowrap"><div align="center"><img src="hartwell_costs.JPG" alt="" width="340" height="147" /></div></td> 
    </tr> 
    </table> 
</form> 
    </body> 
</html> 
<?php 
} 



// check if the form has been submitted. If it has, process the form and save it to the database 
if (isset($_POST['submit'])) 
{ 
// confirm that the 'id' value is a valid integer before getting the form data 
if (isset($_POST['id'])) 
{ 
// get form data, making sure it is valid 

$id = mysql_real_escape_string(htmlspecialchars($_POST['id'])); 
$name = mysql_real_escape_string(htmlspecialchars($_POST['name'])); 
$po_street = mysql_real_escape_string(htmlspecialchars($_POST['po_street'])); 
$po_suburb = mysql_real_escape_string(htmlspecialchars($_POST['po_suburb'])); 
$po_state = mysql_real_escape_string(htmlspecialchars($_POST['po_state'])); 
$po_postcode = mysql_real_escape_string(htmlspecialchars($_POST['po_postcode'])); 
$email = mysql_real_escape_string(htmlspecialchars($_POST['email'])); 
$phone = mysql_real_escape_string(htmlspecialchars($_POST['phone'])); 



// check that firstname/lastname fields are both filled in 
if ($id == '' || $name == '' || $po_street == '' || $po_suburb == ''|| $po_state == '' || $po_postcode == ''|| $email == '' || $phone == '') 
{ 
// generate error message 
$error = 'ERROR: Please fill in all required fields!'; 

//error, display form 
    renderForm($id, $name, $po_street, $po_suburb, $po_state, $po_postcode, $email, $phone, $fax, $error); 
} 
else 
{ 
// save the data to the database 
    mysql_select_db($database_hartwell, $hartwell); 
mysql_query("UPDATE contact SET id= '$id', name='$name', po_street ='$po_street', po_suburb = '$po_suburb', po_state = '$po_state', = po_postcode = '$po_postcode', email ='$email', phone = '$phone', fax = '$fax' WHERE id='$id'") 
or die(mysql_error()); 

// once saved, redirect back to the view page 
header("Location: view.php"); 
} 
} 
else 
{ 
//if the 'id' isn't valid, display an error 
echo 'ID Not Valid!'; 
} 
} 
else 
// if the form hasn't been submitted, get the data from the db and display the form 
{ 

// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0) 
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) 
{ 
// query db 
$id = $_GET['id']; 
    mysql_select_db($database_hartwell, $hartwell); 
$result = mysql_query("SELECT * FROM contact WHERE id=$id") 
or die(mysql_error()); 
$row = mysql_fetch_array($result); 

// check that the 'id' matches up with a row in the databse 
if($row) 
{ 

// get data from db 
$id = $row['id']; 
$name = $row['name']; 
$po_street = $row['po_street']; 
$po_suburb = $row['po_suburb']; 
$po_state = $row['po_state']; 
$po_postcode = $row['po_postcode']; 
$email = $row['email']; 
$phone = $row['phone']; 
$fax = $row['fax']; 


// show form 
renderForm($id, $name, $po_street, $po_suburb, $po_state, $po_postcode, $email, $phone, $fax,''); 
} 
else 
// if no match, display result 
{ 
echo "No results!"; 
} 
} 
else 
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error 
{ 
echo 'No ID Value!'; 
} 
} 
?> 
+1

등호 기호'= po_postcode ='가 있습니다. 그리고'set id = '$ id ''와'id ='$ id''는 하나의 UPDATE에서 조금 이상합니다. 그리고'id'가 숫자이고 그 값을 인용하지 않는다면 MySQL이 당신을 도망 가게하는 나쁜 습관이지만 서버를 더 어렵게 만들뿐입니다. –

답변

1

여기에 등호 제거 : 오류가 바로 오류 메시지와 같은 쿼리 바로이

'$po_state', = po_postcode 

mysql_query("UPDATE contact SET id= '$id', name='$name', po_street ='$po_street', po_suburb = '$po_suburb', po_state = '$po_state', po_postcode = '$po_postcode', email ='$email', phone = '$phone', fax = '$fax' WHERE id='$id'") 
+0

감사합니다. 창고의 초고층 건물을 볼 수 없었습니다. 오식 – Technophobe

4

는 말한다 : 그래서

, = po_postcode = '$po_postcode', 
^
    | 
    + this doesn't belong here 
1

문제는 여기에 있습니다 = po_postcode = '$po_postcode',

관련 문제