Guys iam new to php and iam doing project in php. this is my problem

Parse error: syntax error, unexpected T_STRING in F:\xampplite\htdocs\vidi\add_chemical_save.php on line 7 <<<<

this is my code

<?php
session_start();


  include("config.php");

$chemical name   = mysql_real_escape_string($_POST['chemical name']); // line 7
$quantity        = mysql_real_escape_string($_POST['quantity']);
$type            = mysql_real_escape_string($_POST['type']);
$date            = mysql_real_escape_string($_POST['date']);

$qry_add = "INSERT INTO chemical
             (chemical name, quantity, type, date )
             VALUES ('$chemical name', 'quantity', '$type', '$date') ";

$count = mysql_query("SELECT COUNT(chemical name) FROM chemical WHERE chemical name='$chemical name'");
		if($count==1)
			{
		    echo "<font color=red> Duplicate Entry. Please Verify Chemical name </font>";
			}
			else
			{

		   if($result=mysql_query($qry_add))
		   {
		     echo  '<script language="javascript">';
             echo  'alert("you have successfully added one Chemical!" );';
             echo  '</script>';   
		   }

		   else
		  {
		   echo "<br><font color=red size=+1 >Problem in Adding !</font>" ;
		   echo "ERROR - unable to save new username and password!<br>";
           $SQLError =  "SQL ERROR: ".mysql_errno().".  ".mysql_error()."<BR><BR>";
           echo "$SQLError";
           mysql_close();
				  }
echo " <a href= ' adduser.php ' > click here to add new user </a>" ;			}}?>

    Welcome to PHPBuilder.com! Please use the boards [NOPARSE]

    ...

    [/NOPARSE] tags as it makes your code much easier to read an analyze.

    As for your problem, it is in the variable name, which cannot contain spaces:

    $chemical name

    You have the same error with this variable a few places in the code. I would suggest either removing the space and using camel-case or replacing the space with an underscore.

      thank u very much sir.
      I hv correted as u told. But unfortunately there is another problem.
      hope u will help me in this problem too

      << SQL ERROR: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name, quantity, type, date ) VALUES ('', 'quantity', 'solid', '01'' at line 2 >>

      <?php
      session_start();
            include("config.php");
      
      $chemicalname   = mysql_real_escape_string($_POST['chemical name']); 
      $quantity        = mysql_real_escape_string($_POST['quantity']);
      $type            = mysql_real_escape_string($_POST['type']);
      $date            = mysql_real_escape_string($_POST['date']);
      
      $qry_add = "INSERT INTO chemical
                   (chemical name, quantity, type, date )
                   VALUES ('$chemicalname', 'quantity', '$type', '$date') ";
      
      $count = mysql_query("SELECT COUNT(chemical name) FROM chemical WHERE chemical name='$chemicalname'");
      		if($count==1)
      			{
      		    echo "<font color=red> Duplicate Entry. Please Verify Chemical name </font>";
      			}
      			else
      			{
      
      		   if($result=mysql_query($qry_add))
      		   {
      		     echo  '<script language="javascript">';
                   echo  'alert("you have successfully added one Chemical!" );';
                   echo  '</script>';   
      		   }
      
      		   else
      		  {
      		   echo "<br><font color=red size=+1 >Problem in Adding !</font>" ;
      		   echo "ERROR - unable to add new chemical!<br>";
                 $SQLError =  "SQL ERROR: ".mysql_errno().".  ".mysql_error()."<BR><BR>";
                 echo "$SQLError";
                 mysql_close();
      
      		  }
      
      		}
      ?>
      
      

        It's the same issue. You have a column name in your database with a space (chemical name). Column names cannot have spaces.

          Bonesnap;11000880 wrote:

          Column names cannot have spaces.

          Of course they can! But if they do, you have to delimit them appropriately so that MySQL knows where the identifier starts and stops. For MySQL without ANSI_QUOTES mode enabled, the delimiter you'll want to use is the backtick (`).

          EDIT: Forgot to mention... just because you can use all sorts of exotic characters (such as spaces 🙂) in identifiers, that doesn't mean you should or that doing so is considered a good practice.

          Instead, my first suggestion would be to rename the column so that the use of delimiters are not necessary (e.g. remove the space).

            thanku very much all. Problem solved

              bradgrafelman;11000901 wrote:

              Of course they can! But if they do, you have to delimit them appropriately so that MySQL knows where the identifier starts and stops. For MySQL without ANSI_QUOTES mode enabled, the delimiter you'll want to use is the backtick (`).

              Whoops! Forgot about the backticks. I was taught since day one to never use spaces for such things, and backticks were only to be used for reserved words. I guess you do something (or don't do something) for so long you just kind of forget it.

                Write a Reply...