PHP MySQL problem

Thread Solved

Join Date: May 2007
Posts: 4,444
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: PHP MySQL problem

 
0
  #11
Aug 21st, 2007
Quick aside: Place code tags around code to maintain formatting. It really helps readability.

The part you'll need to change is
  1. $insertSQL = sprintf("INSERT INTO messages (message) VALUES (%s)",
  2. GetSQLValueString($_POST['textarea'], "text"));
I'm not certain how that table is structured, but you will need to add the user id something like this
  1. $insertSQL = sprintf("INSERT INTO messages (userId, message) VALUES (%d,%s)", $userId, GetSQLValueString($_POST['textarea'], "text"));
$userId could be held in the session along with your other properties $_SESSION['userId']. You'll also need to make sure that the query which display the messages returns the user name along with the message and use that instead of the logged in user name from the session.

Does that clear it up a bit?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

Re: PHP MySQL problem

 
0
  #12
Aug 21st, 2007
That worked to a point...i understand what you did, but I don't understand why it's returning a value of 0 (zero) for the userid. Everyone that I insert into the database is giving me the same userid of 0
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,444
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: PHP MySQL problem

 
0
  #13
Aug 21st, 2007
You will need to store the user id in the session when they log in and retrieve it as needed
  1. $userId = $_SESSION['userId'];
Last edited by Ezzaral; Aug 21st, 2007 at 2:54 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: jeffro25 is an unknown quantity at this point 
Solved Threads: 0
jeffro25 jeffro25 is offline Offline
Newbie Poster

Re: PHP MySQL problem

 
0
  #14
Aug 21st, 2007
Now it won't let me enter the user name into the database because it's already there...I'm confued. Keeps telling me 'duplicate entry for key 1'...I double checked the database and it's not set to unique or primary...I now have no idea...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC