좋아, 그래서 부동산 회사를위한 데이터베이스를 구축 중이며, 약 3 ~ 4 개월 전 PHP로 시작했습니다. 이 오류가 발생했습니다. "SQL 구문에 오류가 있습니다. 올바른 구문을 사용하기 위해 MySQL 서버 버전에 해당하는 설명서를 확인하십시오. 'VALUES ('3605 2nd Street ',' ','gfnfgnbfgn ',' MD2 ','21230 ','dfgbfgnbg ',' ',' ','at line 2 '.MySQL 구문 오류, 알아낼 수없는 것 같습니다.
여기 코드가 포함되어 있습니다. 양식이 있으며 POST 메서드를 사용하여이 정보를 전달합니다. 페이지를 참조하십시오.
<?php
session_start();
require('connect.php');
$address = $_POST["Address"];
$apt = $_POST["Apt #"];
$city = $_POST["City"];
$state = $_POST["State"];
$zip = $_POST["Zip"];
$tenant1 = $_POST["Tenant1"];
$tenant1phone = $_POST["Tenant 1 Phone"];
$tenant1email= $_POST["Tenant 1 Email"];
$tenant2 = $_POST["Tenant 2"];
$tenant2phone = $_POST["Tenant 2 Phone"];
$tenant2email= $_POST["Tenant 2 Email"];
$tenant3 = $_POST["Tenant 3"];
$tenant3phone = $_POST["Tenant 3 Phone"];
$tenant3email= $_POST["Tenant 3 Email"];
$daterented = $_POST["Date Rented"];
$rent = $_POST["Rent"];
$leaseexp= $_POST["Lease Expiration"];
$datedue = $_POST["Date Due"];
$vacant = $_POST["Vacant"];
$rentpaid= $_POST["Rent Paid"];
$amountdue = $_POST["Amount Due"];
$fee = $_POST["Fee"];
$secdeposit= $_POST["Security Deposit"];
$leadcert = $_POST["Lead Cert"];
$leadcertdate= $_POST["Lead Cert Date"];
$repairlimit= $_POST["Repair Limit"];
$key = $_POST["Key #"];
$bedrooms= $_POST["Bedrooms"];
$bathrooms = $_POST["Bathrooms"];
$heat = $_POST["Heat"];
$appliances= $_POST["Appliances"];
$owner = $_POST["Owner"];
$owneraddress = $_POST["Owner Address"];
$ownercity = $_POST["Owner City"];
$ownerstate= $_POST["Owner State"];
$ownerzip = $_POST["Owner Zip"];
$ownerphone1 = $_POST["Owner Phone 1"];
$ownerphone2 = $_POST["Owner Phone 2"];
$ownerother= $_POST["Owner Other"];
$owneremail = $_POST["Owner Email"];
$sql = ("INSERT INTO info (Address, Apt #, City, State, Zip, Tenant 1, Tenant 1 Phone,
Tenant 1 Email, Tenant 2, Tenant 2 Phone, Tenant 2 Email, Tenant 3, Tenant 3 Phone,
Tenant 3 Email, Date Rented, Rent, Lease Expiration, Date Due, Vacant, Rent Paid,
Amount Due, Fee, Security Deposit, Lead Cert, Lead Cert Date, Repair Limit, Key #,
Bedrooms, Bathrooms, Heat, Appliances, Owner, Owner Address, Owner City, Owner State,
Owner Zip, Owner Phone 1, Owner Phone 2, Owner Other, Owner Email)
VALUES ('$address', '$apt', '$city', '$state', '$zip', '$tenant1', '$tenant1phone',
'$tenant1email', '$tenant2', '$tenant2phone', '$tenant2email', '$tenant3',
'$tenant3phone', '$tenant3email', '$daterented', '$rent', '$leaseexp', '$datedue',
'$vacant', '$rentpaid', '$amountdue', '$fee', '$secdeposit', '$leadcert',
'$leadcertdate', '$repairlimit', '$key', '$bedrooms', '$bathrooms', '$heat',
'$appliances', '$owner', '$owneraddress', '$ownercity', '$ownerstate', '$ownerzip',
'$ownerphone1', '$ownerphone2', '$ownerother', '$owneremail')");
var_dump($sql);
mysql_query($sql)or die(mysql_error());
if(mysql_affected_rows()>=1){
echo "<p>Entry Added</p>";
echo "<a href='index.php'>Home</a>";
}else{
echo "<p>Entry Not Updated</p>";
}
?>
나는 그것을 통해 검토 한
<?php
session_start();
require('connect.php');
$id = $_GET["id"];
$address = $_POST["Address"];
$apt = $_POST["Apt #"];
$city = $_POST["City"];
$state = $_POST["State"];
$zip = $_POST["Zip"];
$tenant1 = $_POST["Tenant 1"];
$tenant1phone = $_POST["Tenant 1 Phone"];
$tenant1email= $_POST["Tenant 1 Email"];
$tenant2 = $_POST["Tenant 2"];
$tenant2phone = $_POST["Tenant 2 Phone"];
$tenant2email= $_POST["Tenant 2 Email"];
$tenant3 = $_POST["Tenant 3"];
$tenant3phone = $_POST["Tenant 3 Phone"];
$tenant3email= $_POST["Tenant 3 Email"];
$daterented = $_POST["Date Rented"];
$rent = $_POST["Rent"];
$leaseexp= $_POST["Lease Expiration"];
$datedue = $_POST["Date Due"];
$vacant = $_POST["Vacant"];
$rentpaid= $_POST["Rent Paid"];
$amountdue = $_POST["Amount Due"];
$fee = $_POST["Fee"];
$secdeposit= $_POST["Security Deposit"];
$leadcert = $_POST["Lead Cert"];
$leadcertdate= $_POST["Lead Cert Date"];
$repairlimit= $_POST["Repair Limit"];
$key = $_POST["Key #"];
$bedrooms= $_POST["Bedrooms"];
$bathrooms = $_POST["Bathrooms"];
$heat = $_POST["Heat"];
$appliances= $_POST["Appliances"];
$owner = $_POST["Owner"];
$owneraddress = $_POST["Owner Address"];
$ownercity = $_POST["Owner City"];
$ownerstate= $_POST["Owner State"];
$ownerzip = $_POST["Owner Zip"];
$ownerphone1 = $_POST["Owner Phone 1"];
$ownerphone2 = $_POST["Owner Phone 2"];
$ownerother= $_POST["Owner Other"];
$owneremail = $_POST["Owner Email"];
$sql = "UPDATE info
SET
Address='$address',
Apt #='$apt',
City='$city',
State='$state',
Zip='$zip',
Tenant 1='$tenant1',
Tenant 1 Phone='$tenant1phone',
Tenant 1 Email='$tenant1email',
Tenant 2='$tenant2',
Tenant 2 Phone='$tenant2phone',
Tenant 2 Email='$tenant2email',
Tenant 3='$tenant3',
Tenant 3 Phone='$tenant3phone',
Tenant 3 Email='$tenant3email',
Date Rented='$daterented',
Rent='$rent',
Lease Expiration='$leaseexp',
Date Due='$datedue',
Vacant='$vacant',
Rent Paid='$rentpaid',
Amount Due='$amountdue',
Fee='$fee',
Security Deposit='$secdeposit',
Lead Cert='$leadcert',
Lead Cert Date='$leadcertdate',
Repair Limit='$repairlimit',
Key #='$key',
Bedrooms='$bedrooms',
Bathrooms='$bathrooms',
Heat='$heat',
Appliances='$appliances',
Owner='$owner',
Owner Address='$owneraddress',
Owner City='$ownercity',
Owner State='$ownerstate',
Owner Zip='$ownerzip',
Owner Phone 1='$ownerphone1',
Owner Phone 2='$ownerphone2',
Owner Other='$ownerother',
Owner Email='$owneremail'
WHERE id='$id'";
var_dump($sql);
mysql_query($sql)or die(mysql_error());
if(mysql_affected_rows()>=1){
echo "<p>Entry Updated</p>";
echo "<a href='index.php'>Home</a>";
}else{
echo "<p>Entry Not Updated</p>";
}
?>
행을 편집이 페이지에 거의 동일한 문제가 15 번처럼, 그리고 구문 오류를 찾을 수 없습니다. 더 많이 볼수록 거대한 텍스트 벽처럼 보입니다. 더 많은 경험을 가진 사람이 그것을보고 즉시 볼 수 있습니다. 다른 사이트에서 거의 동일한 코드를 사용했지만 아무런 문제없이 유일한 차이점은이 방법이 더 많은 변수라는 것입니다. 미리 감사드립니다.이 사이트와 위대한 사람들은 PHP 학습에 생명의 은인입니다!
당신은 SQL 주입에 열려있어. –
루프를 사용하여 쿼리를 채우십시오. 더 깔끔하고 짧으며 오류가 적습니다. –
'mysql_ *'은 더 이상 사용되지 않습니다. 대신 PDO 또는 MySQLi를 사용하십시오. –