syntax error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #1

    syntax error

    Hi, I have mysql 5.045 installed on my server and i've written a code to insert values into the database. it keeps coming up with this error

    Error in query: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 's within 7 working days of receipt, if the item is not as described.

    ', ' at line 66


    there is nothing wrong with the coding as it's been used and tested on other servers and works perfectly fine....i don't understand why this error is showing. My code is below

    Code:
    <?PHP error_reporting(E_ALL);
    $username="tempsUser";
    $password="auction";
    $database="auctionTemps";
    
    
    $htmlcss=$_POST['htmlcss'];
    $header=$_POST['header'];
    $nav=$_POST['nav'];
    $titleWrap01=$_POST['titleWrap01'];
    $title=$_POST['title'];
    $titleWrap02=$_POST['titleWrap02'];
    $subheadWrap01=$_POST['subheadWrap01'];
    $subheading=$_POST['subheading'];
    $subheadWrap02=$_POST['subheadWrap02'];
    $flashWrap01=$_POST['flashWrap01'];
    $flashWrap02=$_POST['flashWrap02'];
    $flash01=$_POST['flash01'];
    $flashVar=$_POST['flashVar'];
    $flash02=$_POST['flash02'];
    $flashWrap03=$_POST['flashWrap03'];
    $descriptionWrap01=$_POST['descriptionWrap01'];
    $description=$_POST['description'];
    $descriptionWrap02=$_POST['descriptionWrap02'];
    $generalWrap01=$_POST['generalWrap01'];
    $general=$_POST['general'];
    $generalWrap02=$_POST['generalWrap02'];
    $aboutWrap01=$_POST['aboutWrap01'];
    $about=$_POST['about'];
    $aboutWrap02=$_POST['aboutWrap02'];
    $paymentWrap01=$_POST['paymentWrap01'];
    $payment01=$_POST['payment01'];
    $payment02=$_POST['payment02'];
    $paymentWrap02=$_POST['paymentWrap02'];
    $termsWrap01=$_POST['termsWrap01'];
    $terms=$_POST['terms'];
    $termsWrap02=$_POST['termsWrap02'];
    $footer=$_POST['footer'];
    
    
    // OPEN CONNECTION ---> 
    $connection=mysql_connect("localhost","$username", "$password") or die("Unable to connect!");
    
    mysql_select_db("$database") or die("Unable to select database!");
    
    
    //  EXECUTE QUERY ---> 
    $query="INSERT templates (
    
    		    htmlcss, 
                header, 
                nav, 
                titleWrap01, 
                title,
    			titleWrap02,
                subheadWrap01, 
                subheading,
    			subheadWrap02, 
                flashWrap01, 	
                flashWrap02, 
                flash01, 
                flashVar,
                flash02, 
                flashWrap03,
    			descriptionWrap01,
                description, 
                descriptionWrap02,
    			generalWrap01, 
                general, 
                generalWrap02, 
    			aboutWrap01,
                about, 
                aboutWrap02,
    			paymentWrap01, 
                payment01, 
                payment02, 
                paymentWrap02,
                termsWrap01, 
                terms, 
                termsWrap02,
    			footer)
    
            VALUES(	
    		    '".$htmlcss."', 
                '".$header."', 
                '".$nav."', 
                '".$titleWrap01."', 
                '".$title."',
    			'".$titleWrap02."',
                '".$subheadWrap01."', 
                '".$subheading."',
    			'".$subheadWrap02."', 
                '".$flashWrap01."', 	
                '".$flashWrap02."', 
                '".$flash01."', 
                '".$flashVar."', 
                '".$flash02."', 
                '".$flashWrap03."',
    			'".$descriptionWrap01."',
                '".$description."', 
                '".$descriptionWrap02."',
    			'".$generalWrap01."', 
                '".$general."', 
                '".$generalWrap02."', 
    			'".$aboutWrap01."',
                '".$about."', 
                '".$aboutWrap02."',
    			'".$paymentWrap01."', 
                '".$payment01."', 
                '".$payment02."', 
                '".$paymentWrap02."',
                '".$termsWrap01."', 
                '".$terms."', 
                '".$termsWrap02."',
    			'".$footer."')";
    
    //////-----> 
    $result=mysql_query($query) or die("Error in query:".mysql_error()); 
    //if ($result) 
        //echo mysql_affected_rows()." row inserted into the database effectively."; 
    
    //  CLOSE CONNECTION ---> 
    mysql_close($connection); 
    
    /////////////////////////////////////////////////////////////////////////////////// 
    
    ?>
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    If your variable string that is being stored (the one with "...within 7 working days of receipt...") has any single quotes ( ' ) it will stop the code and cause errors.

    Also, I am pretty sure you don't need:
    Code:
    '".$terms."'
    But:
    Code:
    ".$terms."
    Or:
    Code:
    '$terms'
    will be fine. I prefer the second option.

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      ill try that....thanks

      Comment

      • anfetienne
        Contributor
        • Feb 2009
        • 424

        #4
        thanks alot it worked!!!

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          No worries. Glad I could help.

          Comment

          Working...