944,092 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 4575
  • MySQL RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 4th, 2006
0

Help With Messages in Mysql Stop Overwriting

Expand Post »
Hello Pro Programmers!

Can you help me, Please!!!

What I want to do is let my users message each other, I have my form and message page setup I love it! It’s working the messages are going in the right ID’S in the Mysql database, BUT! It is overwriting as soon as the next message is sent.

I want it to save all messages not overwrite any at all and let the user delete the messages as they so wish to delete

Can I do this is it possible? I have it set up so far on mysql MSG with TEXT Do I use blob instead, can you tell me the php code so it does not overwrite in the mysql database and saves all the messages…

Thank-You Pro Programmers, puddin
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
puddin is offline Offline
52 posts
since Mar 2006
Jul 6th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

Could you be using an UPDATE instead of an INSERT statement?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
b225ccc is offline Offline
19 posts
since Jul 2006
Jul 6th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

Thanks so much for your reply,

Now I am trying to use your suggestion , I think you may be right. But with INSERT INTO when I try to add the user id # like in UPDATE I can add the user id -Like this: id='2'");

But with INSERT INTO It does not work! I would appreciate any help again, Thank-you , puddin
Last edited by puddin; Jul 6th, 2006 at 1:48 pm.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
puddin is offline Offline
52 posts
since Mar 2006
Jul 6th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

Ok, this should just be a matter of syntax. For your query, use:

INSERT INTO table_name (id) VALUES ('2')

See here for more in-depth info (my example is a little short to be really useful):
http://www.w3schools.com/sql/sql_insert.asp


Quote originally posted by puddin ...
Thanks so much for your reply,

Now I am trying to use your suggestion , I think you may be right. But with INSERT INTO when I try to add the user id # like in UPDATE I can add the user id -Like this: id='2'");

But with INSERT INTO It does not work! I would appreciate any help again, Thank-you , puddin
Reputation Points: 10
Solved Threads: 1
Newbie Poster
b225ccc is offline Offline
19 posts
since Jul 2006
Jul 6th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

This is what I have , it's not working, it's creating a new id and not going into (id) VALUES ('2')

<?php
include'db.php';
$sql = mysql_query("INSERT INTO myd (id, fm, mg, last_login)VALUES
('$2','$fm','$mg', now())") or die (mysql_error());

if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
echo("");
}
?>

Now in mysql table under fm and mg They Represent: who the message is fm=from and the mg=message : I have them set as a blob: Do you think that is correct?

I did that thinking it could hold a lot of messages : You see I want my users to be able to message each other - and when they click on their message button - They can view all their messages sent by other members -

I want to add a delete button beside each message so the user can delete their messages as they desire.

I have my message form setup great ,

You write your message,
It automatically goes to the mysql table correctly
Postes your message in the right users id -
Than it posts your messsage correctly on the users page
who you sent your message to...

Last it automatically includes that the message is from you...

But when a second message is sent it erases your message. I was using UPDATE now I am trying to use INSERT INTO.

I need mysql table to keep all messages. Users are listed by AUTO INCREMENT 1,2,3 and so on...

I want to allow the user on their message page to see all their messages I want to show a delete button beside each message and let the user delete their messages as they wish.

Thanks again so much, this is the last part of my site so any help again is much appreciated, puddin I also would like the user to recieve an email letting them know, they have a message! I think that part shouldn't be difficult.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
puddin is offline Offline
52 posts
since Mar 2006
Jul 6th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

Is the $2 in your query supposed to be a PHP variable? It may be a typo, but if not I don't think PHP allows a variable to begin with a number.

One trick I used to use a lot when beginning with PHP/MYSQL (not to imply you're a beginner!) is to assign the query string to a variable and then echo the string to make sure it looks like it's supposed to. Like this:

[php]$query = "SELECT * FROM table_name"; //using your query, of course
echo $query;
$result = mysql_query($query);

if (!result) { echo "error with db query!"; }[/php]
In your case, you will be able to see exactly what query your computer thinks your are trying to perform. If that doesn't point you to the problem, post back your intended query in PHP format and then what is echoes to your browser. That $2 seems awfully strange to me though.

-----

As far as the BLOBs go, it's probably the right choice for the message, but depending on what exactly you're storing for the 'from' field, you could probably use VARCHAR (and then you would specify the max number of characters - like 200 or whatever you choose). For instance, if the from field is a username and you specify a maximum length for username as 30 characters, then you would use VARCHAR(30). The VARCHAR type can hold a max of 255 characters.

---

I've used the PHPMailer class (http://phpmailer.sourceforge.net/) without any problems. There may be something better out there now, haven't looked in a year or so.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
b225ccc is offline Offline
19 posts
since Jul 2006
Jul 6th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

I am a beginner 100% I love working with programming a lot, everytime I learn something new I get this big smile!

I have it setup that that the message is viewed before posting but what you have showed is excellent!, thanks,

I'm still trying to get the INSERT INTO to work, I'm hoping it will not overwrite the last message, any other suggestions on that?

Thanks again, puddin
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
puddin is offline Offline
52 posts
since Mar 2006
Jul 6th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

Does the echoed query match what you expected? Can you post the echoed query here? Was the $2 in your original query a typo?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
b225ccc is offline Offline
19 posts
since Jul 2006
Jul 7th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

Sorry about the typo question, no I thought it would work, but it does not nor without it... if I script it like :
INSERT INTO table_name (id) VALUES ('2') It still creates a new ID.

It echos but it creates a new column a new id in my table,
I need it to go into id=2 than it would display on id2's messages page , you see what I mean... and it doesn't work
Last edited by puddin; Jul 7th, 2006 at 12:31 am.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
puddin is offline Offline
52 posts
since Mar 2006
Jul 7th, 2006
0

Re: Help With Messages in Mysql Stop Overwriting

How can I create this message system, I'm trippin out , it has to be possible! I am wondering if I am going about it the right way, gee it's tuff when we don't know uh!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
puddin is offline Offline
52 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Need authoritative source on safety of resetting ft_min_word_len
Next Thread in MySQL Forum Timeline: Desperate again





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC