Insert author(username) variable from forums?

Discussion in 'Databases' started by X.Homer.X, Mar 13, 2008.

  1. #1
    Okay, you guys are gonna hate me for always posting my problems here, but this is where I seem to get my answers the quickest. And i have a doozy of a problem.

    I have a form on my page (below) that i want to submit all the variables that are submitted, plus a hidden one that contains the username of the logged in user.

    
       <form action="includes/insert.php" method="post">
            <div class="row">
                <input name="author" type="hidden" value="<?php $username ?>">
              <div style="float:left; width:64px; line-height:18px;">Title:</div>
              <div style="float:left; width:140px;">
                <input name="title" type="text" class="txt_input">
              </div>
            </div>
    	<div class="row">
              <div style="float:left; width:64px; line-height:18px;">Sub-Title:</div>
              <div style="float:left; width:140px;">
                <input name="subtitle" type="text" class="txt_input">
              </div>
            </div>
            <div class="row">
              <div style="float:left; width:64px; line-height:18px;">Article:</div>
              <div style="float:left;">
                <textarea rows="10" cols="50" name="article" class="txt_area"></textarea>
              </div>
            </div>
         <input name="submit" type="submit" id="submit" value="Create New Article" class="btn_submit" style="margin: 0px 0px 0px 200px;">
       </form>
    
    Code (markup):
    As you can see i want it to input the title, subtitle, content and up the top there, the author. I have a script on my main page that echos the username of the logged in user via this variable $user->data['username']. This is possible because in that script i have a file (config.php) included. I cannot include config.php in this form, or in the insert script (shown below), because it gives me a blank page, with no text or anything. Earlier on in the code i have mad ethe variable $username = #user->date['username'] in hopes that it would remember that and i would be able to return it as the author of the article. This however did not work. Does anyone have any idea how i could do this?

    insert.php
    
    <?php
    $con = mysql_connect("localhost","soldiers_forum","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("soldiers_content", $con);
    
    $sql="INSERT INTO articles (article_title, article_sub, article_content, article_author)
    VALUES
    ('$_POST[title]','$_POST[subtitle]','$_POST[article]','$_POST[author]')";
    
    echo $sql;
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con)
    ?>
    
    Code (markup):
    Any help is greatly appreciated.

    Thanks in advance for any help you may provide :)

    P.S. My forum is phpBB3, and my site is http://soldiersoffortune.darkstargamers.com if you need to see anything on it.

    You wont be able to get to this script because it is protected for admins only.
     
    X.Homer.X, Mar 13, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    I can make it work for you

    Please contact me by pm

    Regards

    Alex
     
    kmap, Mar 13, 2008 IP