#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    Whats worng here?


    this error message appears when i run my code in php

    #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 '19:37:36,jhj,jhjh)' at line 1


    this is the code for the class:

    html Code:
    <script type="text/javascript">
     function changeButton(){	
     if(document.getElementById("name").value !=""){
    	 $("#button1").text("Send to: "+ document.getElementById("name").value);
     }else{
    	 $("#button1").text("Send Message");
     }
    }
      </script>
    </head>
    <body>
    <?php
    if($_GET["op"]=="send_message"){	
    	$to = $_POST["username"];
    	$from = $_SESSION["valid_user"];
    	$time_sent = date('Y-m-d H:i:s');
    	$subject = $_POST["subject"];
    	$message = $_POST["message"];	
    	include("dbConfig.php");
     
    	$enter_mess = "INSERT INTO private_message (to_id,from_id,time_sent,subject,message) VALUES (0,0,$time_sent,$subject,$message)";
     
    //declare in the order variable
    $result = mysql_query($enter_mess) or die(mysql_error());	//order executes
    if($result){
    echo "message sent!!!<br> </br>";	
    	echo $_POST["message"]."<br> </br>";
    }else{echo"error";}
    }else{	
    ?>
     
     
    <form action="?op=send_message" id="send_message" method="POST">
      <fieldset>
      <legend>Message</legend>
     
     
    Username:<br /> <input name="username" type="text" id="name" onkeyup="changeButton()" size="15" /><br />
    Subject:<br /> <input name="subject" type="text" id="subject" size="30" /><br />
     
    Message:<br /> <textarea name="message" cols="50" rows="10" id="message"></textarea>
    <br />
        <button id="button1">Send Message</button>​
            </fieldset>
       </form>
       <script>
    $('textarea').jqte();
    </script>
    <?php }?>
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,260
    Rep Power
    4279
    immediately before you do this --
    Code:
    $result = mysql_query($enter_mess)
    please do this --
    Code:
     echo $enter_mess
    then, copy/paste the actual sql string here, and we'll show you what's wrong with it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0
    this is what came up

    INSERT INTO private_message (to_id,from_id,time_sent,subject,message) VALUES (0,0,2012-11-19 17:29:02,jhj,jhjh)
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,260
    Rep Power
    4279
    there's your problem

    datetime strings need to be enclosed in single quotes

    also, string strings need to be enclosed in single quotes
    Code:
    VALUES ( 0 , 0 , '2012-11-19 17:29:02' , 'jhj' , 'jhjh' )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0
    thankyou that worked

IMN logo majestic logo threadwatch logo seochat tools logo