November 19th, 2012, 11:18 AM
-
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 }?>
November 19th, 2012, 11:24 AM
-
immediately before you do this --
Code:
$result = mysql_query($enter_mess)
please do this --then, copy/paste the actual sql string here, and we'll show you what's wrong with it
November 19th, 2012, 11:29 AM
-
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)
November 19th, 2012, 11:32 AM
-
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' )
November 19th, 2012, 11:35 AM
-
thankyou that worked