INSERT private message system PDO php -


i trying build little private message system in php, using pdo connection database. have got work excpet important part.

i cannot insert message write database love help.

i first post database can see working here. starting users

id int(10) un ai pk  username varchar(30)  password varchar(100)  regdate datetime 

this message table im trying write message to

id int(11) ai pk  from_user varchar(45)  to_user varchar(45)  subject varchar(400)  message text  date date  read tinyint(4)  

i have tried couple of diffrent code work paste code according error check says message succesfully sent...

$sql = " insert private_messages values('',$user,  $to_user','$subject',$message','$date','0') ";      echo "youre message succesfully sent..."; 

but not work , know not right way when using pdo.

i have tried this

$query =$dbh->prepare("insert private_messages(user, to_user, subject,  message, date); values('',$user, $to_user','$subject',$message','$date','0') ");  $query->bindparam(":user", $user); $query->bindparam(":to_user", $to_user); $query->bindparam(":subject", $subject); $query->bindparam(":message", $message);  if ($query->execute()) {     $success = true; } 

but fatal error: uncaught pdoexception: sqlstate[42000]: syntax error or access violation: 1064

i post form im using if can of value

echo " <form action='compose.inc.php' method='post'> <table> <tr> <td>to: </td> <td><input type='text' name='to_user'/></td> </tr> <tr> <td>subject: </td> <td><input type='text' name='subject'/></td> </tr> <tr> <td>message:</td> <td><textarea name='message' rows='10' cols='50'></textarea></td> </tr> <tr> <td></td> <td colspan='2'><input type='submit' name='submit' value='send message'/> </td> </r> </table> </form>    "; 

when doing message system ive been following https://www.youtube.com/watch?v=bed_ymc7qv0 , using mysqli , have been trying decode pdo, think problem lies therein

so short recap error check says message sent. nothing gets written database. im trying use pdo.

if cant find solution love pointers tutorial or books or message system pdo. best regards /robert

instead of inserting variables query binding them.

$query =$dbh->prepare("insert private_messages (user,to_user,subject,message,date) values(:user,:to_user,:subject,:message,now())");  $query->bindparam(":user", $user); $query->bindparam(":to_user", $to_user); $query->bindparam(":subject", $subject); $query->bindparam(":message", $message);  if ($query->execute()) {     $success = true; } 

also should match amount of values amount of columns.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -