If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Inserting value in table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-22-06, 03:03
zoliky zoliky is offline
Registered User
 
Join Date: Aug 2006
Posts: 6
Inserting value in table

I have the following query:

Code:
mysql_query("INSERT INTO messages (id, exped, uid, subiect, message, send_date) VALUES (0, '".$_SESSION['username']."', '".$fetch['user_id']."', '".$_POST['subiect']."', '".$_POST['mesaj']."', NOW())");
The query insert some data to mysql table called "messages".
I have an ID collumn in "messages table" with following option: id INT NOT NULL AUTO_INCREMENT PRIMARY KEY

VALUES (0,.... 0 (the ID) auto increment at every row added to table.

When a new row added to table "messages", I need to get the ID of row and add to another table called "private"

I use this method:

Code:
mysql_query("INSERT INTO messages (id, exped, uid, subiect, message, send_date) VALUES (0, '".$_SESSION['username']."', '".$fetch['user_id']."', '".$_POST['subiect']."', '".$_POST['mesaj']."', NOW())"); 

$msg = mysql_query("SELECT id FROM messages WHERE message='".$_POST['mesaj']."'"); 
$msg_result = mysql_fetch_array($msg);
But is not good idea when $_POST['mesaj'] already exist in table.

Anyone help me a bit ? Any idea?
Reply With Quote
  #2 (permalink)  
Old 08-22-06, 05:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
see the LAST_INSERT_ID function
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On