speckytwat Posted December 1, 2017 Author Share Posted December 1, 2017 (edited) Actually what happens when I change the POST to just $senderid = $_POST['_Sender']; is that although I still get a message saying it was added successfully, when i go into the database table nothing has been added- so removing the intval stops it working. So it works as this (or at least, it adds values to the table - only putting Sender in as 0) $senderid = intval($_POST['_Sender']); But not when I change it to this: $senderid = $_POST['_Sender']; Edited December 1, 2017 by speckytwat Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2017 Share Posted December 1, 2017 I told you why it isn't inserting a record. Read the replies. You output the success message regardless of whether or not the query worked. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 1, 2017 Share Posted December 1, 2017 Yes, I'm getting the success message when the intval is in the code for POST Sender, and I can confirm that the records are added into the db, except that Sender is inputted as zero instead of the username. If I take the intval out of the POST Sender it doesn't work at all I think that is your problem. You are apparently passing the sender username with the post data and trying to populate that as the foreign key for the sender in the messages table. You should be passing the sender ID. My guess is that the 'Sender' field in the table is an integer field. The intval() function is converting the username string to a 0 and allows the query to work. When you remove the intval() conversion, the query is probably failing because you are trying to insert a string into an integer field. Quote Link to comment Share on other sites More sharing options...
speckytwat Posted December 1, 2017 Author Share Posted December 1, 2017 (edited) I double checked, the Sender field in the db is VARCHAR(50)... thanks for the idea though. So not sure where to go with this now - it works with the intval, but only as far as inputting the records (Sender is still going in as 0). When I remove it so it's just inputting a string, it doesn't work at all, regardless of whether or not $sender is inside single quotes or not... Edited December 1, 2017 by speckytwat Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 1, 2017 Share Posted December 1, 2017 Sorry, I'm not sure I understand- there are so many things going on in the thread so I'm not sure which part you're eferring to. Should I have the intval included or not included? If so, what do i need to do in order to have it insert the username rather than an integer (an integer isn't any use to me especially if it's just zero) Or, if I shouldn't include it, then what do I need to do in order to get the INSERT working again? I'm just not clear on that? I did try putting $senderid in single quotes in the INSERT statement but that resulted in no records being inserted, i.e just the same. I don't seem to be any further forward, I just need the sender username inrerted rather than an integer, and for the email notifications to be sent out. Could you let me know what more I need to do to get this set up? It looks like your post came right after mine, so I think you were responding to Barand. Read my last post. It appears you may be trying to insert the 'username' (string) into a field intended for the user ID (integer). You need to use the senders user id, not username. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2017 Share Posted December 1, 2017 How has your messages table been defined? Run this query in your database front end or mysql command line SHOW CREATE TABLE messages;Post the output. Quote Link to comment Share on other sites More sharing options...
speckytwat Posted December 4, 2017 Author Share Posted December 4, 2017 Have just copied it up to the server again and (from testing so far) it appears to now be working - email notifications are going out (and only to sender and recipients) and entered into db correctly. Thanks to everyone for the help and persistence with this. Fingers crossed it will stay working now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.