Breaking down a database insert query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kit
Forum Newbie
Posts: 3
Joined: Sat Mar 27, 2004 12:47 am

Breaking down a database insert query

Post by kit »

I started a thread last night "Changing WebDate Code" but not seeing the light yet I figured I could ask some more questions. Can someone break down this insert query for me?

Code: Select all

q("INSERT INTO dt_messages (sid, rid, subject, message, timesent) VALUES (".$fMemberїid].", $rid, '$subject', '$message', ".(strtotime(date("d M Y H:i:s"))).")");
This is how I translate and what I don't understand, please tell me if I am wrong.

What does the "q" stand for?

"INSERT INTO dt_message" is calling the table.

(sid, rid, subject, message, timesent) is the table column names. What do you think sid and rid stand for?

VALUES (".$fMember[id].", $rid, '$subject', '$message', ".(strtotime(date("d M Y H:i:s"))).")"); are variables collecting values from a form.

Now I changed to code (to below) to simply add a fixed subject and message but it did not insert anything into the database. Please tell me what I did wrong?

Code: Select all

VALUES (".$fMemberїid].", $rid, 'Virtual Kiss', 'You have been Virtual Kissed', ".(strtotime(date("d M Y H:i:s"))).")");
Thanks for your help.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

My stab in the dark

q is a variable that someone messed up on, i think it probably

$q = "sql command";

("INSERT INTO dt_messages (sid, rid, subject, message, timesent) VALUES (".$fMember[id].", $rid, '$subject', '$message', ".(strtotime(date("d M Y H:i:s"))).")");

INSERT is the sql command, dt_messages is the table in a database that u connected too, sid appears to be a auto_inc column, the first part
(sid, rid, subject, etc etc) is just paths declaring the order of the next part (the actual variables) to be inserted into the SQL table.
so sid column would get the variable $fmember[id] placed into it n so forth.

sid and rid could mean for anything, this is why u should learn n write your OWN code and NOT copy others that you do not understand..

If you dont know the values, you probably dont even know what your sql table attriubues are. you should learn SQl =]
Post Reply