2012-02-21 220 views
-1

這是向房地產列表數據庫提交列表的簡單形式。這是我第一次這樣做,所以如果你注意到我正在做的事情是不好的做法或以任何方式愚蠢,請讓我知道。解析錯誤:語法錯誤,意外的T_IF,期待','或';'

反正到錯誤我得到:

Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in C:\Program Files\EasyPHP-5.3.9\www\addform.php on line 62 

我沒有看到,是缺少分號任何行,62行是if語句....這是什麼錯誤呢?

<?php 
//set database login variables 
require_once 'login.php'; 

//connect to server 
$db_server = mysql_connect($db_hostname, $db_username, $db_password); 

//all server access lines have to be dealt with better than this. See page 227. Probably create a function. 

//Note to self: look into try/catch in php 

if (!$db_server) die("Unable to connect to database: " . msql_error()); 

mysql_select_db($db_database, $db_server) or die('Unable to select database: ' . mysql_error()); 
$submitted = false; 

//Checking if values were passed 
if (isset($_POST['area']) && 
    isset($_POST['type']) && 
    isset($_POST['price']) && 
    isset($_POST['bedrooms']) && 
    isset($_POST['fullbath']) && 
    isset($_POST['halfbath']) && 
    isset($_POST['sqft'])) 
    //if passed, set variables accordingly 
    { 
     $area = get_post('area'); 
     $type = get_post('type'); 
     $price = get_post('price'); 
     $bedrooms = get_post('bedrooms'); 
     $fullbath = get_post('fullbath'); 
     $halfbath = get_post('halfbath'); 
     $sqft = get_post('sqft'); 
     $submitted = true; 
    } 
//optional field 
if (isset($_POST['remarks'])) 
    { 
     $remarks = get_post('remarks'); 
    } 
else 
    {$remarks = '';} 
//form HTML 
echo <<<_END 
    <form action="addform.php" method="post"> 
    Area: <select name="area" size="1"> 
     <option value="Hoboken">Hoboken</options> 
     <option value="Jersey City">Jersey City</options> 
     <option value="Weehawken">Weehawken</options> 
    </select><br /> 
    Type: <select name="type" size="1"> 
     <option value="rent">Rental</options> 
     <option value="sale">Sale</options> 
     <option value="commercial">Commercial</option> 
    </select><br /> 
    Price: <input type="text" name="price" /><br /> 
    Bedrooms: <input type="text" name="bedrooms" /><br /> 
    Full Bathrooms: <input type="text" name="fullbath" /><br /> 
    Half Bathrooms: <input type="text" name="halfbath" /><br /> 
    Square Feet: <input type="text" name="sqft" /><br /> 
    Remarks: <textarea name="remarks" wrap="soft" /><br /> 
    <input type="submit" value="Add Listing" /> 
    </form> 
    <br /> 
    <br /> 
_END 
//if data was provided, insert it into database and confirm 
if ($submitted) { 
    $query = "INSET INTO bix (area, type, price, bedrooms, fullbath, halfbath, sqft, remarks) VALUES('$area', '$type', '$price', $bedrooms', '$fullbath', '$halfbath', '$sqft', '$remarks')"; 
    if (mysql_query($query)){ 
     echo "listing inserted.<br /></br />"; 
    } else { 
     echo "insert fail: $query <br /><br />"; 
    } 
} 
+0

只注意到我從來沒有關閉數據庫 - 但我不認爲這會導致解析錯誤? – mavix 2012-02-21 23:17:24

+0

你可能錯過了一個;在第62行。 – ppp 2012-02-21 23:19:59

+0

mavix:1)這是一個解析錯誤。先解析,然後執行。 2)當腳本結束時,PHP將自動關閉它。 – 2012-02-21 23:20:28

回答

0

那麼,你的$查詢確實存在問題。

$query = "INSET INTO bix (area, type, price, bedrooms, fullbath, halfbath, sqft, remarks) VALUES('$area', '$type', '$price', $bedrooms', '$fullbath', '$halfbath', '$sqft', '$remarks')"; 

INSET也許應該INSERT,你想'$bedrooms'代替$bedrooms'

除此之外,你缺少一個分號的閉幕後_END

4

你在這裏的echo後缺少一個分號:_END

2

你最肯定if語句之前缺少;。 61線?

相關問題