AWithers04 Posted September 14, 2008 Share Posted September 14, 2008 Hello everyone, I am very new to PHP and basically learned alot on my own. ??? I am creating a message board for a website and the user has to log in to post a message. the database has 2 fields...Name and Comment. I have created a form with an insert query to submit the message to the db....what i would like it to do is automatically post the logged in users name to the Name field when they submit the message. How can i go about doing this. Also i am using Dreamweaver CS3 Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 14, 2008 Share Posted September 14, 2008 Well, where is the username stored when they log in? In many cases the username is stored to a session variable such as $_SESSION['username']. So, when the user submits a comment, just use that variable. Example: $query = "INSERT INTO table (name, comment) VALUES ('{$_SESSION['username']}', '{$_POST['commnet']}')"; Quote Link to comment Share on other sites More sharing options...
AWithers04 Posted September 14, 2008 Author Share Posted September 14, 2008 Here is my insert code for the comment....where should i call the session variable and in what syntax? if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO comments (Comments) VALUES (%s)", GetSQLValueString($_POST['comment'], "text")); mysql_select_db($database_HiddenRidge, $HiddenRidge); $Result1 = mysql_query($insertSQL, $HiddenRidge) or die(mysql_error()); } Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 14, 2008 Share Posted September 14, 2008 Well the query would look something like this: $insertSQL = sprintf("INSERT INTO comments (Name, Comments) VALUES (%s, %s)", GetSQLValueString($_SESSION['username'], "text"), GetSQLValueString($_POST['comment'], "text") ); But, I don not know your database or where you are storing the username - if you even are. Make sure you know that the column names in the query are correct and that you are properly accessing the username. Quote Link to comment Share on other sites More sharing options...
AWithers04 Posted September 14, 2008 Author Share Posted September 14, 2008 that worked perfectly. Thank you very much for your help. Greatly appreciated 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.