Data not getting insert in to table

Dear All

Please see the below script.

I am getting the error msg;

Mysql error, data not saved, try again -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 ‘’ at line 7

Please help



<?php 
 
// PUT YOUR DATABASE CONNECTION SCRIPT HERE 
$host="localhost"; // Host name 
 
$username="root"; // Mysql username 
 
$password=""; // Mysql password 
 
$db_name="merchandising"; // Database name 
 
// Connect to server and select databse. 
 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 
mysql_select_db("$db_name")or die("cannot select DB"); 
 
echo "connected"; 
 
 
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
  <meta http-equiv="content-type" content="text/html; charset=windows-1251">  
  <style>  
    .errText {  
        font-family: Arial;  
        font-size: 13px;  
        color: #CC0000;  
        text-decoration: none;  
        font-weight: BOLD;  
    }  
  </style>  
  <title></title>  
  </head> 
  <body>   
  <?php 

      $factory = $_POST['factory'];
      $fdepartment = $_POST['fdepartment'];
      $designation = $_POST['designation'];
      $mrchand_name = $_POST['mrchand_name'];
      $errSecret_code="";
      $errUniqkey = "";
      
      $errors       = ""; 
      $displayform = '1'; 


 
      if($_POST["ac"]=="login"){  // start of login if 
        // Full Name must be letters, dash and spaces only  
        if (!$factory) { 
        $errFactory = '<p class="errText">Please select your Factoy.</p>';       
         $error = 'YES';
        }
    
        if (!$fdepartment) { 
        $errFdepartment = '<p class="errText">Please select your Department.</p>';       
         $error = 'YES';
        }
    
        if (!$designation) { 
        $errDesignation = '<p class="errText">Please select your Designation.</p>';       
         $error = 'YES';
        }
    
        if (!$mrchand_name) { 
        $errMrchand_name = '<p class="errText">Please select your Name.</p>';       
         $error = 'YES';
         }
         
         if(preg_match("/^crossmerkajal2011$|^mehidy1$|^mehidy2$|^mehidy3$|^mehidy4$|^mehidy5$/", $_POST["secret_code"]) === 0){
         $errSecret_code = '<p class="errText">Secret code; Your secret code is not matching, be remind secret code is your identity.</p>';
          $error = 'YES';      
                }
         if(preg_match("/^[0-9\\"\\']+$/", $_POST["uniqkey"]) === 0){
          $errUniqkey = '<p class="errText">Uniq key must be in digits</p>';
          $error = 'YES';
        }
    
        
 
        if ($error != 'YES'){ // only insert data if no errors 
           $displayform = '0'; // disable form show 
           $factory = mysql_real_escape_string($_POST['factory']); 
           $fdepartment = mysql_real_escape_string($_POST['fdepartment']); 
           $designation = mysql_real_escape_string($_POST['designation']); 
           $mrchand_name = mysql_real_escape_string($_POST['mrchand_name']); 
           $secret_code = mysql_real_escape_string($_POST['secret_code']); 
           $uniqkey = mysql_real_escape_string($_POST['uniqkey']); 
           
           //$query = "INSERT INTO $tbl_name(id,name,address,email,passport,phone,zip,date,user,pass) VALUES ('null',
           
           $sql = mysql_query("INSERT INTO newcomp 
                                       SET   factory = '$factory', 
                                             fdepartment = '$fdepartment', 
                                             designation = '$designation', 
                                             mrchand_name = '$mrchand_name', 
                                             secret_code = '$secret_code', 
                                             uniqkey = '$uniqkey', 
                                             "); 
          if (!$sql) {  
           echo 'Mysql error, data not saved, try again -' . mysql_error();               
           $displayform = '1'; // show form to try again 
          }else{ 
              echo 'Your data was inserted'; 
          } 
 
        } // end of insert if 
      } // end of  login if 
 
  if ($displayform = '1') { // only show form if required 
 
  ?>  
  <center>  
  <form name="main" action="<?php $PHP_SELF ?>" method="POST">  
    <input type="hidden" name="ac" value="login">  
    <table width="1200" border="0" cellpadding="4" cellspacing="0" bordercolor="#000000" bgcolor="#EDEFF1">  

      <tr align="center">  
        <td colspan="6"><strong style="font-size:18px">Add New Order</strong></td>  
      </tr>  
      
        <TR>
    <TD style="VERTICAL-ALIGN: top" vAlign=top align=center colSpan=6 height=18> 
    <SPAN>Today: <?php print(Date("l F d, Y")); ?>

      
      <script type="text/javascript" language="javascript1.5">
   <!-- Hide script from old browsers
   
      window.onload = theClock

      function theClock() {
         now = new Date;
         theTime = ((now.getHours() > 0 && now.getHours() < 13)) ? now.getHours() : (now.getHours() == 0) ? 12 : now.getHours()-12;
         theTime += (now.getMinutes() > 9) ? ":" + now.getMinutes() : ":0" + now.getMinutes();
         theTime += (now.getSeconds() > 9) ? ":" + now.getSeconds() : ":0" + now.getSeconds();
         theTime += (now.getHours() < 12) ? " am" : " pm";
         
         clockSpan = document.getElementById("myClock");
         clockSpan.replaceChild(document.createTextNode(theTime), clockSpan.firstChild);         
         
         setTimeout("theClock()",1000);
      }                                               

   // End hiding script from old browsers -->
   </script>   
   , Now: <span id="myClock">?</SPAN>                     
     </TD></TR>
<tr align="center" bgcolor="FD9003">  
   <td colspan="6" bgcolor="#A6B39D">Factory Details</td>  
      </tr>  
     
     <tr align="center" bgcolor="#FD9003">  
        <td colspan="6" bgcolor="#919B93">
          <?php  if(isset($errFactory)) echo $errFactory; ?>
          <?php  if(isset($errFdepartment)) echo $errFdepartment; ?>  
          <?php  if(isset($errDesignation)) echo $errDesignation; ?>  
          <?php  if(isset($errMrchand_name)) echo $errMrchand_name; ?>  
          <?php  if(isset($errSecret_code)) echo $errSecret_code; ?>  
          <?php  if(isset($errUniqkey)) echo $errUniqkey; ?>  
          </td>  
      </tr>  

<tr>
<th>Factory Name<font style="color: #800517; font-size: 105%;"><b>*</font><br><font style="color: #666666; font-size: 60%;"> </font></th>
<th>Department<font style="color: #800517; font-size: 105%;"><b>*</font><br><font style="color: #666666; font-size: 60%;"> </font></th>
<th>Designation<font style="color: #800517; font-size: 105%;"><b>*</font><br><font style="color: #666666; font-size: 60%;"> </font></th>
<th>Merchandiser Name<font style="color: #800517; font-size: 105%;"><b>*</font><br><font style="color: #666666; font-size: 60%;"> </font></th>
<th>Secret Code<font style="color: #800517; font-size: 105%;"><b>*</font><br><font style="color: #666666; font-size: 60%;">Secret Code is Your Identity</font></th>
<th>Unique Key<font style="color: #800517; font-size: 105%;"><b>*</font><br><font style="color:#0101DF; font-size: 75%;">

<?php
$query = mysql_query("SELECT MAX(uniqkey) FROM `newcomp`");
$results = mysql_fetch_array($query);
$cur_auto_id = $results['MAX(uniqkey)'] + 1;

echo "$cur_auto_id";

?>
</font></th>
</tr>

<tr>
<td align="center">
<select name="factory" value="<?php echo $factory;?>">
<option value="Crosswear Ind Ltd" <?php if($factory=="Crosswear Ind Ltd") echo(" selected=\\"selected\\"");?> >Crosswear Ind Ltd</option>
</select>          
</td>

<td align="center">
<select name="fdepartment" value="<?php echo $fdepartment;?>">
<option value="Merchandising" <?php if($fdepartment=="Merchandising") echo(" selected=\\"selected\\"");?> >Merchandising</option>
</select>          
</td>

<td align="center">
<select name="designation" value="<?php echo $designation;?>">
<option value="">Select...</option>
<option value="Merchandising Manager" <?php if($designation=="Merchandising Manager") echo(" selected=\\"selected\\"");?> >Merchandising Manager</option>
<option value="Merchandising Inchagr"<?php if($designation=="Merchandising Inchagr") echo(" selected=\\"selected\\"");?> >Merchandising Inchagre</option>
<option value="Sr.Merchandiser"<?php if($designation=="Sr.Merchandiser") echo(" selected=\\"selected\\"");?> >Sr.Merchandiser </option>
<option value="Merchandiser"<?php if($designation=="Merchandiser") echo(" selected=\\"selected\\"");?> >Merchandiser </option>
<option value="Trainee Merchandiser"<?php if($designation=="Trainee Merchandiser") echo(" selected=\\"selected\\"");?> >Trainee Merchandiser </option>

</select>          
</td>

<td align="center">
<select name="mrchand_name" value="<?php echo $mrchand_name;?>">
<option value="">Select...</option>
<option value="Mr.Sultan Mahmud" <?php if($mrchand_name=="Mr.Sultan Mahmud") echo(" selected=\\"selected\\"");?> >Mr.Sultan Mahmud</option>
<option value="Mr.Kajal Pasha"<?php if($mrchand_name=="Mr.Kajal Pasha") echo(" selected=\\"selected\\"");?> >Mr.Kajal Pasha</option>
<option value="Mr.Mehidy Hassan"<?php if($mrchand_name=="Mr.Mehidy Hassan") echo(" selected=\\"selected\\"");?> >Mr.Mehidy Hassan</option>
<option value="Mr.Rayhan"<?php if($mrchand_name=="Mr.Rayhan") echo(" selected=\\"selected\\"");?> >Mr.Rayhan </option>
<option value="Mr.Bikash"<?php if($mrchand_name=="Mr.Bikash") echo(" selected=\\"selected\\"");?> >Mr.Bikash </option>
<option value="Mr.Rony"<?php if($mrchand_name=="Mr.Rony") echo(" selected=\\"selected\\"");?> >Mr.Rony </option>

</select>          
</td>


<td align="center">
<input type="password" name="secret_code" value="<?php echo $_POST["secret_code"]?>" size="15" /></td>
</td>

<td align="center">
		<input type="text" name="uniqkey"  value="<?php echo $uniqkey;?>" size="15" />
</td>

</tr>

      <tr align="center">
        <td colspan="6"><input type="submit" name="Submit" value="Submit"><input type="reset" name="reset" value="Reset"></td>
      </tr>  


</table>



  </form>
  
 <a href="http://www.mehidy.com" target="_blank">Mohammad Mehidy Hassan</a><br>Live on: mehiddy@hotmail.com  
      
    
  </center>  
<?php  
  } // end of form display if 
?> 
  </body>  
</html>


Try removing that last comma (this: , ):
uniqkey = ‘$uniqkey’,

Othewise mysql might be thinking it should be expecting another value. I’m not saying this will fix it but so far its the only thing standing out at me.

Dear Tangoforce

Thank you very much. Its working.