I am at my wits end ! Dont know what's wrong with the following code. It is always saying "Parse error: syntax error, unexpected $end in C:\Program Files\EasyPHP-\www\addallbuy.php on line 51"

<?Php

mysql_connect("localhost","root");
mysql_select_db("landshop_clientdata");

$Date = Date("Y-m-d");
$Agt="Landshoppe";
$user="anitg";
$Title="Mr.";
$first="Anit";
$last="Gopinath";
$Age="40";
$prop="Wanted 1 BHK/2BHK and other properties";
$phone="9833157945";
$email="anit@landshoppe.com";
$Trans="Any";
$Propt="Any";
$Area="0";
$Units="Any";
$Price="0";
$Add="Please register and add property";


$query = 'SELECT city FROM cities';

$result =mysql_query($query);

while ($info = mysql_fetch_array($result))


	{

	{echo $info['city'];echo"<br>";}

	$Loca=$city;


	$sql="INSERT INTO clientdata (Date,Agent_Ind,username,Title,Firstname,Lastname,Age,phone,Email,propheading,Transaction, PropertyType,Area, Units,Price, Location, AdditionalData)
	VALUES($Date,$Agt,$user,$Title,$first,$last,$Age,$phone,$email,$prop,$Trans,$Propt,$Area,$Units,$Price,$Loca,$Add)”;

	$result2=mysql_query($sql);

	if ($result)

	{echo 'Updated';}


}

?>

Dani AI

Generated

correctly identified the immediate cause: the INSERT string in the file contains a non-ASCII (typographic/smart) closing quote, so PHP never sees the end of that string and hits end-of-file with an open string. That alone will produce the "unexpected $end" parse error. Typing the quote again with a plain ASCII " (U+0022) fixes the parse error.

There are a few other bugs worth fixing while the code is being cleaned up:

  • The city value is never read into $Loca — use the fetched row ($info['city']) instead of an undefined $city.
  • The VALUES list in the INSERT is built with raw PHP variables and no quoting/escaping; that will break SQL and is a security risk. Use prepared statements or at least escape and quote strings.
  • The code tests if ($result) after the INSERT, but $result is the earlier SELECT; test the INSERT result instead.
  • Extra/braced blocks around the echo are unnecessary and make the flow harder to follow.
  • The old mysql_* API is deprecated/removed in modern PHP; migrate to PDO or mysqli and enable error reporting so failures are visible.

Example (safe, minimal) using PDO and prepared statements:

<?php
try {
    $pdo = new PDO('mysql:host=localhost;dbname=landshop_clientdata;charset=utf8mb4','root','');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $cities = $pdo->query('SELECT city FROM cities');
    $insert = $pdo->prepare(
        'INSERT INTO `clientdata` (`Date`,`Agent_Ind`,`username`,`Title`,`Firstname`,`Lastname`,`Age`,`phone`,`Email`,`propheading`,`Transaction`,`PropertyType`,`Area`,`Units`,`Price`,`Location`,`AdditionalData`)
         VALUES (:date,:agent,:user,:title,:first,:last,:age,:phone,:email,:prop,:trans,:propt,:area,:units,:price,:loca,:add)'
    );

    $common = [
      ':date'=>date('Y-m-d'), ':agent'=>'Landshoppe', ':user'=>'anitg', ':title'=>'Mr.',
      ':first'=>'Anit', ':last'=>'Gopinath', ':age'=>40, ':phone'=>'9833157945',
      ':email'=>'anit@landshoppe.com', ':prop'=>'Wanted 1 BHK/2BHK and other properties',
      ':trans'=>'Any', ':propt'=>'Any', ':area'=>0, ':units'=>'Any', ':price'=>0,
      ':add'=>'Please register and add property'
    ];

    while ($row = $cities->fetch(PDO::FETCH_ASSOC)) {
        $common[':loca'] = $row['city'];
        $insert->execute($common);
    }

} catch (PDOException $e) {
    echo 'DB error: '.$e->getMessage();
}
?>

Quick troubleshooting: run php -l addallbuy.php to lint for syntax errors; enable error_reporting(E_ALL) and ini_set('display_errors',1) while debugging; retype suspicious quotes in a plain-text editor (smart quotes often come from Word/HTML). This addresses the parse error and prevents subsequent SQL/runtime issues for .

The closing double-quote for your MySQL query on line 39 is actually the wrong character.
It should be a " and you have a , so the string is never closed and eats the rest of your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.